Javascript API documentation

For AI and campaign script related discussions and questions
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Javascript API documentation

Post by milo christiansen »

Per wrote:structButNoWallsInArea --> not needed
killStructsInArea --> not needed, use removeObject(xx, true)
numDroidsInArea --> not needed
droidInArea --> not needed
flushConsoleMessages --> not needed?
numStructsInArea --> not needed
createAlliance --> use setAlliance(p1, p2, bool)
breakAlliance --> not needed, see above
destroyFeature --> not needed, see removeObject(xx)
vanishUnit --> not needed, see removeObject(xx)
getDroidCount --> not needed
addFeature --> addFeature added
setAssemblyPoint --> setAssemblyPoint added
First things first: structButNoWallsInArea How are you supposed to simulate this? get a list of all structures and iterate over it checking x/y or can you specify an area already and I missed that?

The same thing applys to all the xxInArea functions

I must have been having a brain fart when I included getDroidCount :roll:

As for flushConsoleMessages that was questionable from the start.
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

enumRange() the size of the area, check if you got what you want in it?
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Javascript API documentation

Post by milo christiansen »

enumRange is far too restrictive. For example you can't do a rectangle, and the docs read like it only list things that you can see.

What is needed is a full range of enumXInArea functions that are identical to the normal enumX functions except for taking 4 numeric coords
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

enumArea() function would be good, with options to specify which players (ENEMIES, ALLIES, etc) and optionally restricted to a looking player. The results array could then be scanned to check for specific unit/structure types.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Javascript API documentation

Post by milo christiansen »

Ahh but I don't want to have to scan an array for specific results I want to be able to do things like

Code: Select all

if (enumDroidsInArea(player,x,y,x2,y2).length < 1)
{
    // All units in area dead
}
*Sigh* not particularly realistic considering the fact that the most common use case is structButNoWallsInArea which would require filtering out the walls in any case :annoyed:

so I guess a generic enumArea() would be OK but a filter param for type as well as player would be invaluable.
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

milo christiansen wrote:the docs read like it only list things that you can see.
:shock: omg really?
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Javascript API documentation

Post by milo christiansen »

Returns an array of game objects seen within range of given position that passes the optional filter
It may just be a mistake...
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: Javascript API documentation

Post by Duha »

Per wrote:I am starting to generate the API documentation for the new scripting system based on Javascript. It is in a PDF where most of its content is automatically generated from documentation inside the source code. This is a work in progress - it is not recommended to start working with this scripting system yet.

However, if you have any feedback on the documentation or the API design, feel free to post your thoughts in this thread.

The new scripting system is already being used to determine winners and losers, set up bases and starting techs, and control scavengers. I am also in the process of converting the Semperfi AI to the new system -- it currently builds some trucks and does some research, and that is about it. Be patient, please :lecture:

Master docs autogenerated by the buildbot:
One page: http://buildbot.wz2100.net/files/javasc ... cript.html
Multi page table of contents: http://buildbot.wz2100.net/files/javasc ... index.html
Hi, I want to make some sugustions about api but I dont know how to test it on my machine.
Can you create tutorial how to make changes and test them.
Some question:
Q: I want to add console('It works') to game start event, and observe it in game. How to do it?
Q: I made changes to research event, whent it will be reloaded? At the begining new game or instantly?

PS. How did you autogenerate docs. Adding some javascript(jQuery) to it will allow to have table of contents and dock in one page.
http://addons.wz2100.net/ developer
cybersphinx
Inactive
Inactive
Posts: 1695
Joined: 01 Sep 2006, 19:17

Re: Javascript API documentation

Post by cybersphinx »

Duha wrote:How did you autogenerate docs.
With hevea, see https://github.com/Warzone2100/warzone2 ... ile.am#L70.
We want information... information... information.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

@Duha:
Q: I want to add console('It works') to game start event, and observe it in game. How to do it?
Take a look at this tutorial: https://warzone.atlassian.net/wiki/disp ... rst+AI+mod

If you put the console() in the start event, you'll never see it because you won't be able to go in to cheat mode, open the debug menu and switch to the right player fast enough after the game starts. So you need to do a timer in the start event to call another function after a few seconds (that function then does the console() message) in order to give yourself enough time to switch to the right player.
Q: I made changes to research event, whent it will be reloaded? At the begining new game or instantly?
Your script gets reloaded when a game starts (or is loaded from a savegame): https://warzone.atlassian.net/wiki/disp ... pt+changes
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

milo christiansen wrote:
Returns an array of game objects seen within range of given position that passes the optional filter
It may just be a mistake...
enumRange used to only give you visible objects. I just changed it, so that it can give you all objects within range that pass the filter if you add another optional parameter and make it false.
API documentation wrote:enumRange(x, y, range[, filter[, seen]]
If you want shorter and more to the point versions of enumRange(), you could make wrapper functions around it in javascript? Seems like a nicer way to do it, than to make lots variations of the C++ functions.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

@milo: You could use something like this: https://warzone.atlassian.net/wiki/page ... Id=4816931

That approach will adapt to JS API version as well, so if enumRange is available it'll use that, otherwise it'll do a few extra steps and use the more basic enumStruct and enumDroid functions to get the same results.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Duha
Trained
Trained
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: Javascript API documentation

Post by Duha »

cybersphinx wrote:
Duha wrote:How did you autogenerate docs.
With hevea, see https://github.com/Warzone2100/warzone2 ... ile.am#L70.
insert to header to make table of contents
Spoiler:
Thanks a lot. It works :)
http://addons.wz2100.net/ developer
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

@Duha there's a table of contents for the online JS API docs:

* http://buildbot.wz2100.net/files/javasc ... index.html

And also a contents page for my version of the docs:

* https://warzone.atlassian.net/wiki/display/jsapi/API
* https://warzone.atlassian.net/wiki/disp ... i/Contents
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: Javascript API documentation

Post by milo christiansen »

@per OK that should work for round/square areas but what about rectangles? I still thing a enumArea(x, y, x2, y2, "playerfilter", "type filter", seen) would be best, then I can just write wrappers for specific uses.

@aubergine Some kind of wrapper will be needed in (almost) any case but I don't think I'll need as much effort into backwards compatibility.
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual