AI methods in JS

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
aracer
Average
Average
Posts: 9
Joined: Mon Nov 02, 2009 1:26 am

AI methods in JS

Post 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?
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Post 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.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Post 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.
aracer
Average
Average
Posts: 9
Joined: Mon Nov 02, 2009 1:26 am

Post 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!
Post Reply