Javascript API documentation

For AI and campaign script related discussions and questions
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

@milo: If your mod is for Warzone 3.2+ then you can use the full range of functions in the API. However if it needs to work on 3.1 as well, there are several API features that won't be available - such as enumRange(), although I believe Per might have plans to port that to the 3.1 branch...?
"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:@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.
Added enumArea(<x1, y1, x2, y2 | label>[, filter[, seen]]. (You can call it with x, y, x2, y2 replaced with an area label. This should work, but I have not been able to test this yet.)
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Just noticed that i seriously miss two things:
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

@NoQ: https://warzone.atlassian.net/wiki/page ... Id=4817005 <-- generic "removeObject()" function in 3.2 can remove anything from the map :)
"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 That should do fine :)
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 »

Bump: somebody is asking for a JS function to make those flashy red lights, similar to what you see on LZ in campaign.

P.S. Per: i know you're there, looking to see you in chat a lot, cause i have a ton of questions :oops:
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

@NoQ - I am pretty busy with other things at the moment. I try to read what is posted on the forum ... but that is it for now.
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Ok nvm, sure it's ok.
Probably the most curious one is that we just accidentally found out that js groups are broken ... :oops:
User avatar
Andrie
Regular
Regular
Posts: 533
Joined: 20 Jun 2012, 14:11
Location: Suid Afrika

Re: Javascript API documentation

Post by Andrie »

@Per
javascript.pdf wrote:A number of very good guides to JavaScript exist on the Internet.
I a wanted to PM you but I can't, so let me ask you here where can I get good guides please tell me.
"My IRC en multiplay naam is Andrie"

Groete Andrie
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

NoQ wrote:somebody is asking for a JS function to make those flashy red lights, similar to what you see on LZ in campaign.
Nevermind.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

NoQ wrote:Just noticed that i seriously miss two things:
This should be covered by removeObject(object[, special effects?]), which sadly is 3.2 only.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Added new events (3.2 only):

eventGameLoaded() - An event that is run when game is loaded from a saved game. There is usually no need to use this event.

eventGameSaving() - An event that is run before game is saved. There is usually no need to use this event.

eventGameSaved() - An event that is run after game is saved. There is usually no need to use this event.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

Yessssss!!!!!!!!! :D

For 3.1 branch, I was wondering if I created a global getter/setter property, when saving it should trigger the getter and thus I can backport the eventGameSaving() event to 3.1 branch? But how would I know what order it reads the global properties in... first defined first saved, or saved alphabetically? I assume it accesses them in the order they are defined, doing a for..in on the global object/scope? And I'm guessing that events & timers will be disabled during the save process, so I can queue a function call to eventGameSaved() to backport that event too? Hrm... Oooh, I've just thought of a better way to backport eventGameLoaded() as well... *back to coding*

EDIT: When getting variables to save, does the WZ engine differentiate between data and accessor properties? I'm hoping it doesn't? How does it work out which globals to save and which not to save (other than obvious things like constants and functions)?

EDIT #2: I've made a start on documenting the key environment sequences that occur within Warzone, from a JS scripter's perspective: https://warzone.atlassian.net/wiki/disp ... +Sequences
"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 »

Chat messages going between AIs and between humans and AIs, even if human is on a different computer than AI, should work now in master (3.2+).
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

:D :D :D
NullBot 2.0, for which chat support was planned as a improvement worth bumping first digit, is coming soon, i guess (:

(close #3199?)