Page 1 of 1

AI methods in JS

Posted: Fri Dec 18, 2009 11:53 pm
by aracer
I'd like to code purely in JS, yet there are some methods which are seemingly only available using legacy AI scripts - eg performFlyToRangeFromDestination, performFaceDestination to mention just the two I needed to use recently. This inevitably results in having to mix scripts if you want to use the more advanced stuff only available through JS. Is there some way to run commands like this from JS that I'm missing, or if not, are there plans to incorporate stuff like this into JS so coding can become more consistent?

Posted: Sat Dec 19, 2009 12:11 am
by JensAyton
AIs will retain their current form through the next stable release. After that, there is the outline of a plan to add a Javascript AI system. An effect of this will be to make all AI methods available to Javascript.

Posted: Sat Dec 19, 2009 8:40 am
by Thargoid
The best way at the moment is to twin together an AI plist and a JS script. There is the AI command sendScriptMessage and the js command reactToAIMessage which allows the two to interact and steer each other.

Plus you can use the JS commands setAI and switchAI to change the AI the entity is currently using (with or without leaving the old one on the stack) and AIState to switch states within the current AI (ATTACK_SHIP, GLOBAL, FLEE or your own custom states etc).

Have a look in some of my OXPs (Drones, Captured Thargons, Aquatics to name but three) to find some examples of those in use, plus OXPs by Eric Walch and several other people.

Posted: Sat Dec 19, 2009 10:09 am
by aracer
Thanks - that's exactly what I did, Thargoid, as I couldn't see any other way. It's just that it seems rather clumsy and I was wondering if there was an alternative!