Javascript API documentation

For AI and campaign script related discussions and questions

Re: Javascript API documentation

Postby Per » 20 May 2013, 23:09

I understand. The goal should be that "scripts never break".

I am just not sure how to ensure this, in general, when it is the underlying multiplayer data and rules that change.

We could trap old IDs and translate to new ones in the code, I suppose. One ID translation table might solve many such future problems, maybe.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3561
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Postby Duha » 20 May 2013, 23:22

Per wrote:I understand. The goal should be that "scripts never break".


Can you explain me what it means in warzone2100 context?
http://addons.wz2100.net/ developer
User avatar
Duha
Trained
Trained
 
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: Javascript API documentation

Postby Per » 20 May 2013, 23:59

That scripts built for older versions of Warzone keep working in the future.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3561
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Postby CDR Manuel » 21 May 2013, 00:30

Unfortunately, if the scripts keep breaking due to implementation of new content. You're faced with an ultimatum, remake them from scratch, or find ways to add on to the code and hope for the best. At this point, adding on will just add on garbage, you really need to consider flagging down the master snapshot and remake the entire code to better suit the new API.

I'm sorry, but when there are too many compatibility issues, there's really no choice.
CDR Manuel
Rookie
Rookie
 
Posts: 24
Joined: 09 Nov 2012, 14:37

Re: Javascript API documentation

Postby aubergine » 21 May 2013, 01:11

As long as there's a way to determine what version of the API you're working with (often by examination of specific functions, globals or constants) then in JS it's relatively straight forward to handle the changes in the API. Problems arise when something changes in such a way that it's very difficult for a .js script to determine whether it's in an environment before or after that change.

It's also important to note that the changes we are currently experiencing are part of a process to deal with some age old problems in terms of the WZ architecture. Due to limited time availability, it's not possible to do re-writes - it's generally better to nudge things in the right direction over several iterations. While this can be frustrating for modders affected by the changes, it has the advantage of maintaining WZ's evolution, without which devs, modders and end-users alike would probably lose interest.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
aubergine
Professional
Professional
 
Posts: 3459
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Postby NoQ » 21 May 2013, 05:42

Per wrote:I am just not sure how to ensure this
Well, so, ... what do you think about the proposal above? It can help quite a lot. If we eliminate dead links, our scripts will always find something with that name.

I can try making a patch this weekend; it will also probably help in nicely resolving this issue.
User avatar
NoQ
Special
Special
 
Posts: 6042
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Postby Per » 21 May 2013, 07:47

NoQ wrote:Well, so, ... what do you think about the proposal above? It can help quite a lot. If we eliminate dead links, our scripts will always find something with that name.

I can try making a patch this weekend; it will also probably help in nicely resolving this issue.

I am not sure it will work quite like you think. Even if you populate the internal data structures with duplicates, these duplicates won't be enabled, researched and upgraded like the originals, since only the original IDs will be targeted.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3561
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Postby Duha » 21 May 2013, 09:00

aubergine wrote:As long as there's a way to determine what version of the API you're working with (often by examination of specific functions, globals or constants) then in JS it's relatively straight forward to handle the changes in the API. Problems arise when something changes in such a way that it's very difficult for a .js script to determine whether it's in an environment before or after that change.

It's also important to note that the changes we are currently experiencing are part of a process to deal with some age old problems in terms of the WZ architecture. Due to limited time availability, it's not possible to do re-writes - it's generally better to nudge things in the right direction over several iterations. While this can be frustrating for modders affected by the changes, it has the advantage of maintaining WZ's evolution, without which devs, modders and end-users alike would probably lose interest.


IMHO it is good idea to make high level js api over current api. It will help to make small changes in low level api with out breaking old mods.

It should be object based api (like https://developers.google.com/maps/docu ... erence#Map). I has some expirience with maps, I like this api approch.

I don`t like current api. It takes too many chars to do simple things. (see high level implementation of distBetweenTwoPoints https://github.com/haoNoQ/nullbot/blob/ ... js.inc#L23) There is some other good ideas as cache. Adding standart js library will make mod development more easy and api changes more smooth.
http://addons.wz2100.net/ developer
User avatar
Duha
Trained
Trained
 
Posts: 287
Joined: 25 Mar 2012, 20:05
Location: SPb, Russia

Re: Javascript API documentation

Postby NoQ » 21 May 2013, 20:26

Per wrote:I am not sure it will work quite like you think. Even if you populate the internal data structures with duplicates, these duplicates won't be enabled, researched and upgraded like the originals, since only the original IDs will be targeted.
Yeah right :oops: :oops: :oops:
User avatar
NoQ
Special
Special
 
Posts: 6042
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Postby NoQ » 06 Jun 2013, 06:46

I'm not quite understanding how the new cyborg body system works with cyborg engineers. What i see now is that while trying to produce cyborg engineers my AI produces walking legs without bodies and throws them into attack (believing their droidType is CYBORG). Same applies to mechanics, i guess, but im not using them.
User avatar
NoQ
Special
Special
 
Posts: 6042
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Postby NoQ » 09 Jun 2013, 07:42

completeResearch(...) seems to do nothing unless surrounded by hackNetOn/hackNetOff, when it causes a desync on trying to use the technology (bug or feature?)

P.S. trying to use it from rules.js.
User avatar
NoQ
Special
Special
 
Posts: 6042
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Postby Per » 09 Jun 2013, 10:00

NoQ wrote:completeResearch(...) seems to do nothing unless surrounded by hackNetOn/hackNetOff, when it causes a desync on trying to use the technology (bug or feature?)

Did you make sure it is called simultaneously on all clients?
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3561
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Postby NoQ » 09 Jun 2013, 13:06

Aha, i think i know what's wrong. I'm running it from eventStructureBuilt in rules.js (trying to make building a structure unlock technologies); it is only called for the current player.

I wonder what other events are called for the current player only when defined in rules.js.
User avatar
NoQ
Special
Special
 
Posts: 6042
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Postby Per » 02 Aug 2013, 21:10

Added new function setReticuleButton(id, tip, filename, filenameDown) that defines the look and tooltip of the reticule buttons. The filenames are the ones found in data/base/images/, with no path. Callbacks and stuff will be added later.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3561
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Postby Per » 10 Aug 2013, 20:42

Added new function syncRequest(req_id, x, y, obj1, obj2) and new event eventSyncRequest(from, req_id, x, y, obj1, obj2). This unassuming pair allows you to synchronize javascript functions that would otherwise cause desync in a game, as any sync request that is generated is a tiny bit later triggered as an event simultaneously on all clients (and all scripts!). Great care must be taken to define only sync requests that can be validated against attempts at cheating. For example, if for some reason a sync request is defined that allows a player to order a unit to hold position, you must check that the request comes from the player that own this droid. Any unused parameter can be filled with null or zero; the obj parameters can be omitted.

It would have been nice to have a varargs for this function, but I saw no nice way to implement that.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
 
Posts: 3561
Joined: 03 Aug 2006, 19:39

PreviousNext

Return to Scripting