Page 2 of 25
Re: Javascript API documentation
Posted: 07 Jan 2012, 12:22
by Per
vexed wrote:They had a reason for all that ugliness...
What was that reason?
Re: Javascript API documentation
Posted: 09 Jan 2012, 17:20
by milo christiansen
I did some prelim planing for cam 4 porting and it looks like I need at least:
setScrollParams
addStructure
setDroidKills
addMessage
startMission
removeDroid
One function that would be nice would be:
droid GetDroidFromID(ID int)
but the new map embedded names functionality looks very cool so it would mostly be to make porting easier

Re: Javascript API documentation
Posted: 09 Jan 2012, 21:31
by Per
Implemented setScrollParams, addStructure and loadLevel (was startMission).
What is the purpose (use for) of setDroidKills?
I will need more time to implement addMessage(), as I wish to do that properly.
Re: Javascript API documentation
Posted: 10 Jan 2012, 05:51
by Goth Zagog-Thou
setDroidKills was to make the Tac Sergeant a Sergeant when the campaign starts.

Re: Javascript API documentation
Posted: 11 Jan 2012, 15:56
by NoQ
I'm looking for
random() ...
upd: Found it,
Math.random() 
Re: Javascript API documentation
Posted: 12 Jan 2012, 02:48
by aubergine
would orderDroidStatsLoc() be more intuitive if named orderDroidBuild() ?
Re: Javascript API documentation
Posted: 12 Jan 2012, 02:50
by aubergine
What's the difference between me and selectedPlayer - won't they always be the same?
Re: Javascript API documentation
Posted: 12 Jan 2012, 08:55
by Per
No. me == player running the script. selectedPlayer == player currently being controlled by the human player at this client. For AI scripts, it is usually always the case that me != selectedPlayer.
Re: Javascript API documentation
Posted: 12 Jan 2012, 17:52
by aubergine
Does the droidCanReach() function use pathfinding (ignoring player structures) to find out if a droid can get from A to B? If so, would it be possible to instead of just returning true/false to return an object {accessible:<boolean>, dist:<distance>} ?
Reason: I plan on doing some checks with certain droid tasks to ensure they can get to destination from where they are, but often will also be doing distBetweenTwoPoints afterwards - it would be nice if, having already done hard work in droidCanReach(), I could get more accurate distance from droidCanReach() and thus not have to call distBetweenTwoPoints().
Re: Javascript API documentation
Posted: 12 Jan 2012, 19:00
by Per
aubergine wrote:Does the droidCanReach() function use pathfinding (ignoring player structures) to find out if a droid can get from A to B?
No. It uses cached data. So it is very fast, but somewhat limited.
Re: Javascript API documentation
Posted: 12 Jan 2012, 19:04
by aubergine
Does the cache include some info on distance of the path though? Even if it's not overly accurate, it would enable me to see if the actual path from A to B is much longer than distBetweenTwoPoints and act accordingly...
BTW, thanks for your patience & help!
Re: Javascript API documentation
Posted: 12 Jan 2012, 19:24
by Per
No, it does not.
Re: Javascript API documentation
Posted: 12 Jan 2012, 20:17
by Per
aubergine wrote:would orderDroidStatsLoc() be more intuitive if named orderDroidBuild() ?
Yes. Good idea. I have made the change, but left an alias for orderDroidStatsLoc to give you time to change your scripts.
Re: Javascript API documentation
Posted: 12 Jan 2012, 20:47
by Per
milo christiansen wrote:
setDroidKills
droid GetDroidFromID(ID int)
I have added an 'experience' property to droids, and setDroidExperience(droid, experience) to set it. Note that in wzscript, the value passed in to setDroidKills() would get multiplied by 100, but not divided by the same amount when returned with getDroidKills()... Now it is not multiplied by anything, so you may need to change the value you intended to pass in. (The value is read with floating point precision.)
droidFromId(id) also added. Pass in an ID, get a droid out. If you feel the need to use this for new code, you are doing something wrong. Avoid using, please

Re: Javascript API documentation
Posted: 12 Jan 2012, 21:13
by NoQ
Suppose i store a droid in a global variable, and this droid dies. How can a script notice that?