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 »

I previously grumbled about the game objects being static snapshots of game data - with the work I'm doing on my Vault script, I've gained a new understanding and appreciation for why the decision was made to have game objects copy game data rather than expose it live to scripts.

So, just wanted to take back my earlier comments and say 'well done!' on an erudite decision with regards to the game objects exposed via JS API.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

I wasn't really reading much last week ... did i miss anything? :oops:

I'm still looking for a way of making AI 1. chat and drop and receive beacons, 2. make use of gateways drawn on the map, and 3. know where his units are currently going (expose .orderx and .ordery properties?) ... also, challenge trouble not fixed yet in v3.1beta1 (:
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

By the way, how exactly do we produce cyborg engineers?

Code: Select all

buildDroid(struct, "Truck", "Cyb-Bod-ComEng", "CyborgLegs", "", DROID_CONSTRUCT, "CyborgSpade");
didn't work, says

Code: Select all

[js_buildDroid] Invalid template Truck for factory A0CyborgFactory
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

No idea, but watching this will cheer you up: https://www.destroyallsoftware.com/talks/wat
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Emdek
Regular
Regular
Posts: 1329
Joined: 24 Jan 2010, 13:14
Location: Poland

Re: Javascript API documentation

Post by Emdek »

aubergine, funny, but if you think about those examples, at least some of them are logical. :-D
Also there are far "worse" examples, more similar to languages like one here, censored by forum...
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.


Beware! Mad Qt Evangelist.
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:By the way, how exactly do we produce cyborg engineers?

Code: Select all

buildDroid(struct, "Truck", "Cyb-Bod-ComEng", "CyborgLegs", "", DROID_CONSTRUCT, "CyborgSpade");
didn't work, says

Code: Select all

[js_buildDroid] Invalid template Truck for factory A0CyborgFactory
That should work. Can you open a bug ticket for it?
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

Done: #3133 (:
User avatar
NoQ
Special
Special
Posts: 6226
Joined: 24 Dec 2009, 11:35
Location: /var/zone

Re: Javascript API documentation

Post by NoQ »

What are the return values of functions like orderDroidBuild or buildDroid?

Cause i just noticed that i intuitively rely on them to return true if the order was successful and false if it's impossible to comply, which sometimes seems to be wrong (?)
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

I'd also like to better understand the return values of the various functions. I was trying to work out what they'd be from the .cpp files, but I don't know C++ well enough to work out what's going on.
"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 »

I'm currently a bit too busy with apartment renovation to do much with the source, and my dev box is down, but in general, if you look in the c++ source, anything that has 'return QScriptValue();' returns nothing, and anything with 'return QScriptValue(true);' or 'return QScriptValue(false);' returns a boolean result value.

If you find such things missing in the documentation, I'd be happy to take patches to improve it.
User avatar
aubergine
Professional
Professional
Posts: 3462
Joined: 10 Oct 2010, 00:58

Re: Javascript API documentation

Post by aubergine »

Ah, cool - it was the QScriptValue() that I wasn't sure about and your post above explains how that works so I can work out the rest.
"Dedicated to discovering Warzone artefacts, and sharing them freely for the benefit of the community."
-- https://warzone.atlassian.net/wiki/display/GO
User avatar
Emdek
Regular
Regular
Posts: 1329
Joined: 24 Jan 2010, 13:14
Location: Poland

Re: Javascript API documentation

Post by Emdek »

Information on what script returns (especially if those are objects / arrays) is "must have" in documentation (only other useful things are examples, but those should wait for completion of current scripting redo phase - initial porting to JS). ;-)
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.


Beware! Mad Qt Evangelist.
User avatar
Goth Zagog-Thou
Regular
Regular
Posts: 1582
Joined: 06 Jan 2007, 08:08
Location: Delta Base

Re: Javascript API documentation

Post by Goth Zagog-Thou »

Looks like the time has come to convert Cam 4 to the new scripting engine. :P

Are there any unimplemented functions that might hinder this process yet?
User avatar
Emdek
Regular
Regular
Posts: 1329
Joined: 24 Jan 2010, 13:14
Location: Poland

Re: Javascript API documentation

Post by Emdek »

AFAIK campaign related functions are not done yet.
Nadszedł już czas, najwyższy czas, nienawiść zniszczyć w sobie.
The time has come, the high time, to destroy hatred in oneself.


Beware! Mad Qt Evangelist.
Per
Warzone 2100 Team Member
Warzone 2100 Team Member
Posts: 3780
Joined: 03 Aug 2006, 19:39

Re: Javascript API documentation

Post by Per »

Many campaign related functions have been ported already, but few of them tested - at all. If you want to help out, testing these functions would be of good help to getting the campaign side of things moving along. Then of course there are many campaign functions that are not yet ported, such as no function yet for adding a message, playing a video, etc..