NationStates Jolt Archive


Scripting...

Brezhnev
20-01-2004, 05:22
Could someone please post a link that explains how to write scripts for NationStates.
SalusaSecondus
20-01-2004, 07:16
As far as I know, there are no threads on how to write scripts. In the moderation forum, there is a thread detailing what is and isn't permitted ( http://www.nationstates.net/forum/viewtopic.php?t=111038 ), though you can always ask me if you are unsure (or want an exception).. Scripts can be writting in literally any computer language that can access the internet. I'd recommend starting there and deciding which language to work in.

This isn't a project for the faint hearted. Though an interesting idea would be to create an interpreted NS Control language (project for some people out there? I'll lend a hand if you do).


http://www.weirdozone.0catch.com/projects/nationstates/salusasecondus/salusasecondus2.jpg
SalusaSecondus
Tech Modling
PGP: 0x0604DF3E
Ballotonia
20-01-2004, 10:37
This isn't a project for the faint hearted. Though an interesting idea would be to create an interpreted NS Control language (project for some people out there? I'll lend a hand if you do).

Actually, building this into Tcl commands wouldn't be difficult at all (I script using Tcl). What kind of functionality were you thinking of?

Ballotonia
SalusaSecondus
20-01-2004, 10:50
This isn't a project for the faint hearted. Though an interesting idea would be to create an interpreted NS Control language (project for some people out there? I'll lend a hand if you do).

Actually, building this into Tcl commands wouldn't be difficult at all (I script using Tcl). What kind of functionality were you thinking of?

Ballotonia

I was thinking about defining a simple script (ie interpreted) language for the sole purpose of controlling NationStates. Once designed, different people could write interpreters for it, thus, it could run on any platform. The interpreters would be platform specific. As the game evolves the backend can be changed to deal with this, but the scripts could remain the same.
Ackbar
20-01-2004, 16:01
Sharing script code is an interesting idea. As yet they have ben treated as meats for the victors, which I think is somewhat realistic. But sharing the scripts is an interesting idea, and could obviously have some postive results.
Juxtapositions
20-01-2004, 20:39
Here are some ideas for functions for the interpreter. I grabbed these from a library of functions I have to work with NationStates.
All parameters and returns are strings. If you need a number then convert.

Region Information Functions
region= whereami(nationname)
count= regioncount(regionname)

Nation Information Functions
population= nationpop(nationname)
name= nationlastactive(nationname)
animal= nationanimal(nationname)
currency= nationcurrency(nationname)
economy= nationeconomy(nationname)
freedoms= nationfreedoms(nationname)
rights= nationrights(nationname)


Nation Control Functions
sessionhandle= login(nationname, password)
postmessage(sessionhandle, Message)
sendtelegram(sessionhandle, TargetNationName, Message)
movenation(sessionhandle, TargetRegion)
logout(sessionhandle)
The Basenji
20-01-2004, 20:43
When in trouble, when in doubt, Google (www.google.com) it.
Naleth
21-01-2004, 02:04
Juxtapose, you have a goo collection of functions for doing things, but don't forget about getting information?
(getTelegrams(sessionHandle), getCivilHQ(region), ect)
Qaaolchoura
21-01-2004, 04:03
This isn't a project for the faint hearted. Though an interesting idea would be to create an interpreted NS Control language (project for some people out there? I'll lend a hand if you do).
If I manage to finish my half dozen other unfinished projects, and my father finally teaches me Java (which he's promised for some time and never done. QBasic and HTML are not good scripting languages {you likely can't write an internet controlling script in either of them}), I'd love to help.

Maybe if it is ongoing, I could join this summer?
Juxtapositions
21-01-2004, 04:15
Juxtapose, you have a goo collection of functions for doing things, but don't forget about getting information?
(getTelegrams(sessionHandle), getCivilHQ(region), ect)

Sure, add as you want. Just trying to get talking about what kind of interface the scripting language should be and what kind of funcitonality it should take on.
I'm throwing out functions because it's easier for people to argue against a concrete idea than to throw around a concept. I like the idea of functions because that's what I'm comfortable with and that's the way I would approach it.

I was wondering if it shouldn't be more english like. For example:

1.) Get Telegrams for nation juxtapositions into telegramlist;
2.) Write telegramlist into LocalFile "TMs.txt"
3.) Move juxtapositions to the heartland;
4.) Post "Juxtapositions is now here, lock up your children"

I could see some serious advantages to this.
SalusaSecondus
21-01-2004, 05:24
I would probably build it off of Pascal/Delphi syntax and make it object oriented.

[code:1:15f44b4476]
var
SalusaSecondus as Nation;
begin
SalusaSecondus.login("SalusaSecondus", "myPassword");
for i = 1 to SalusaSecondus.telegrams.length do
begin
Print SalusaSecondus.telegrams[i]
end;
end;[/code:1:15f44b4476]

Hmm, upon further consideration, this may not be trivial by any stretch of the imagination.

Edit: Doing this functionally might be much easier, but we'd still need to implement control structures such as loops and conditionals.

Edit2: You know? Maybe BASIC should be out model?
Phoebos
21-01-2004, 11:42
I think the OO approach is a far nicer way of going about it, although I have next to no expereince with Pascal/Delphi. Java's really the best bet if we want it to be platform independent... I think creating a new interpreted language is, as you say, not trivial by any stretch of the imagination.

I might take a look at trying to define an Object Model for this... it's an intregueing idea. Also, if we used this as a basis for most scripts, controls could be prebuilt into the scripts to comply with the rules of scripting.
Arnarchotopia
21-01-2004, 12:26
Sharing script code is an interesting idea. As yet they have ben treated as meats for the victors, which I think is somewhat realistic. But sharing the scripts is an interesting idea, and could obviously have some postive results.

There are some very good reasons why certain information should be kept secret. :evil:
Juxtapositions
21-01-2004, 13:31
The one consistent theme I'm getting in this thread is that although people think it's a neat idea no one really has the time to work on it. In reality why would we? Anyone who's looking at this seriously has already done most if not all the functionality they need in their language/compiler of choice so why spend a huge amount of effort to create an interpreted language that may or may not be used?

If we're going to create something that could be used to "script" functionality for nationstates we should probably abandon the idea of creating an interpreted language and just come up with a library of functions that could be used with a given language. That way all of the basic loop/variables and normal programming support would already be built in. Also a large number of tools for a given language probably exist already so it woulod be easier for someone to get a start . This goes along with Phoebos's idea of creating an object model for Java.

We should be able to get a good head start this way by people donating functions for a Java packagethat could be worked into a given object model. I am advocating Java becuase it seems to be the language of choice for thse coming out of college, is platform independant (kind of), and can be run on the client side so that no server is required to run the code.
Phoebos
21-01-2004, 18:10
Sounds good to me. Also a good excuse for me to get up to date with my java programming. In any case, a library of functions could be ported quite easily to other languages if necessary (I for one will probably port a lot to .Net for use in PNP2)
21-01-2004, 18:29
I'd like to play along as time permits. I can bring modest java and vb skills to the party, no functional Pascal or Delphi though.
SalusaSecondus
21-01-2004, 18:52
A Java package sounds like a good idea. I'd definitely want to review it, and would have some requirements for how it is implemented, but I think that it is a good idea.
1 Infinite Loop
22-01-2004, 00:18
The only problem I have with Java is it is unstable and generally likes to crash browsers and freeze OS's, if it can be made stable, then groovy.
1 Infinite Loop
22-01-2004, 00:20
The only problem I have with Java is it is unstable and generally likes to crash browsers and freeze OS's, if it can be made stable, then groovy.
Brezhnev
22-01-2004, 03:44
If I could interrupt your barinstorming session a bit, I would probably try to use Perl for my script, since that's what I know best (although that isn't saying much).
Aldomina
22-01-2004, 04:03
Java is cool...I use it every day...It is easy to use, easy to program, easy to implement, moderately error free...If help is needed I will lend a hand. After all, this game has given me hours and hours of enjoyment, if I can give something back I would be happy to. :D
25-01-2004, 07:18
Java applets are screwy and error prone.

Java applications only screw up when the programmer screw up, at least on Windows and Linux JREs.

I'd definately go with Java for this, already have the OO scheme and it's pretty easy to pick up for the would-be-scripters.

I'm not quite sure how you could get at the information that requires a nation to be logged in (telegrams, settings, etc.)... Cookies would be... interesting... to implement.

-The Disordered Orderer
The value of X cannot be known
Goobergunchia
25-01-2004, 19:29
#tag#
Naleth
26-01-2004, 07:27
I'd definetly be interested in seeing a java package for this. I'm one of those people whose gonna be coming out of college in a few years knowing java ;) ... can't help much right now, though. Just got started like a month ago.
Ackbar
26-01-2004, 08:13
The one consistent theme I'm getting in this thread is that although people think it's a neat idea no one really has the time to work on it. In reality why would we? Anyone who's looking at this seriously has already done most if not all the functionality they need in their language/compiler of choice so why spend a huge amount of effort to create an interpreted language that may or may not be used?


Essentialy to make it easier. Like a cheeseburger. beyond that, I can see no reason.
Greater Crawford
30-01-2004, 21:50
Greater Crawford
30-01-2004, 21:50
Anyone who's looking at this seriously has already done most if not all the functionality they need in their language/compiler of choice so why spend a huge amount of effort to create an interpreted language that may or may not be used?

If we're going to create something that could be used to "script" functionality for nationstates we should probably abandon the idea of creating an interpreted language and just come up with a library of functions that could be used with a given language. That way all of the basic loop/variables and normal programming support would already be built in. Also a large number of tools for a given language probably exist already so it woulod be easier for someone to get a start . This goes along with Phoebos's idea of creating an object model for Java.

We should be able to get a good head start this way by people donating functions for a Java packagethat could be worked into a given object model. I am advocating Java becuase it seems to be the language of choice for thse coming out of college, is platform independant (kind of), and can be run on the client side so that no server is required to run the code.

If I did this on my own, I would probably use PHP because of its good support for internet operations, as well as its existing HTML and XML parsing modules. Java would probably be slightly better for an OO approach, although the parsing might be harder. Although the portability of a client-side-only approach is a bonus, I would suggest a server-side version as well, to make it more accessible to those with less experience. Many NSers do not know how to run a command-line tool with Java, PHP, Perl, etc.
31-01-2004, 06:34
Java has a rich set of internet classes already implemented, as well as decent HTML and XML parsers.

Implementing the actual parsing for the scripting language would be equally difficult with any language I would imagine. My main conern would be how logging into nations would be handled. My understanding is that NS currently manages this solely through cookies, which are not trivial to implement in any programming language I'm aware of (save, perhaps, VisualBasic). To get this started, much less finished, xml streams would need to be provided that allow you access to telegrams/issues/dossier etc. easily.

As soon as you have those, getting information becomes a snap:

URL u=new URL("http://www.nationstates.net/private_nationdata.cgi/nation=mynation/password=mypassword);
Object o=u.openConnection().getContent();

...and then have some fun with it. (note that this is really rough example).

-The Disordered Orderer
X>=0