(info) Other great resources: Official JS API docs, Scripting Forum

Finally found the JS API

I've been searching for some time to properly locate the JS API. Everything pointed to it being on the global object (at least that's where the C++ source code says it's putting it) but so far it's been elusive.

My previous attempts had focussed on Object.getOwnPropertyNames() which:

Returns an array of all properties (enumerable or not) found upon a given object.

Note the bold bit: enumerable or not.

I knew the JS API declarations were almost certainly non-enumerable, after all they weren't showing up in a "for..in" loop. So I expected that getOwnPropertyNames() would do the trick and unearth them, but to no avail - instead it just gave me a list of the normal JS stuff like Date, Math, etc.

So, I decided to give Object.keys() a try, which:

Returns an array of all own enumerable properties found upon a given object

Strangely, this is what delivered the goods (click image to zoom):

So, it seems that the ECMA-262 implementation used by the Warzone API has some bugs when used on the global object:

  • Object.getOwnPropertyNames(obj) doesn't list non-enumerable stuff (I tried this by defining my own non-enumerable stuff and confirmed the bug)
  • Object.keys(obj) doesn't filter out non-enumerable stuff

I'm not too fussed about these bugs, they don't affect normal stuff that you do with your script (by that I mean they work on all normal objects), but just thought I'd post this info in case anyone else is digging deep in to the Warzone JS environment and JS API.

As well as all the expected properties, doing this also unearthed "gc" and "print" (both functions I assume) that are likely part of the Spidermonkey JS environment rather than warzone.

Anyway, this now means that I have a much easier way to check what's been exposed by the JS API for different versions of the game, which will make cross-version scripting so much easier.