...
Code Block | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
[player_2] team = 1 difficulty = "Medium" position = 4 ai = semperfi.js |
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.
The droid ob ject that you receive here has multiple properties that can be accessed to learn more about it. These propertie are read-only, and cannot be changed. In fact, ob jects that you get are just a copies of game state, and do not give any access to changing the game state itself.
Events
The code in a javascript file is triggered by specially named functions called Events.
...