enumerating JS API features

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

enumerating JS API features

Post by aubergine »

Hi,

Anyone know how I can enumerate all the JS API functions / properties defined in the scripting environment?

I can check for existence of one using something like this:

Code: Select all

if (!!chat) console("yay, we can chat");
But how do I get a list of all the functions/properties defined by JS API, from within my script, in the environment in which my script is running?

"for (i in this)" on the global scope just tells me what's in the global object. Likewise (just incase you were about to mention the enumerable flag) "Object.getOwnPropertyNames(this)" on the global scope doesn't list any of the JS API stuff either.

Any ideas?
"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: enumerating JS API features

Post by milo christiansen »

I wrote a script that prints the API for my JavaScript host (which also uses QScript) using a for-in loop to enumerate all the functions and properties.

The secret is to make the function take an object parameter and pass it "this" from the global scope, then call the function recursively on everything for which typeof === "object" :)

or you could make it use "this" as the object if nothing is passed in :wink:
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: 3459
Joined: 10 Oct 2010, 00:58
Contact:

Re: enumerating JS API features

Post by aubergine »

I found that in QtScript the Object.getOwnPropertyNames() behaves oddly on the global object ("this" from the global scope) and in the end found I could enumerate the JS API features using Object.keys().

I documented my travels:

https://warzone.atlassian.net/wiki/page ... Id=1671765

https://warzone.atlassian.net/wiki/disp ... the+JS+API

I'd be interested to learn more about your script.
"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: enumerating JS API features

Post by milo christiansen »

I'll post a copy soon :wink:
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
User avatar
milo christiansen
Regular
Regular
Posts: 749
Joined: 02 Jun 2009, 21:23
Location: Perrinton Michigan

Re: enumerating JS API features

Post by milo christiansen »

Sorry I forgot :oops:

Anyway here is the copy promised.
Attachments
Print API.js
(749 Bytes) Downloaded 192 times
In general, if you see glowing, pulsating things in the game, you should click on them.
- Demigod Game Ganual
Post Reply