...
Excerpt |
---|
Warzone2100 contains a scripting language for implementing AIs, campaigns and some of the game rules. |
...
It uses JavaScript, so you should become familiar with this language before proceeding with this document. A number of very good guides to JavaScript exist on the Internet.
Game rules and Scavenger AI
The following hard-coded files exist for game rules that use this API:
- multiplay/skirmish/rules.js – Default game rules including base setup, starting re-search, winning and losing.
- multiplay/script/scavfact.js – If scavengers are active, this script controls their actions.
It's worth looking at both these files as they contain lots of useful code that might be of use in your scripts. Also, you can create mods to overwrite these files if desired.
![(warning)](/wiki/s/807751700/6452/20faa45e8c4c41f1fc842bb030f6b19d3baf00e0/_/images/icons/emoticons/warning.png)
...
.. |
...
...
...
...
...
...
Challenge scripts
...
...
...
...
...
...
...
Working with enumerated lists
One error that it is easy to make upon initially learning JavaScript and using this API, is to try to use the ’for (... in ...)’ construct to iterate over an array of ob jects. This does not work! Instead, use code like the following:
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
var droidList = enumDroid(me,DROID_CONSTRUCT); // get a list of trucks
for (var i = 0; i < droidList.length; i++) {
var droid = droidList[i];
// ... do stuff with the droid ...
} |
The above code gets a list of all your construction droids (trucks), and iterates over them one by one.
...