Posted: Sun Aug 05, 2007 1:59 pm
I now have ship scripts reacting to events and talking to each other. My test case involves a ship with three escorts. When the mothership is attacked (by anyone), it tells its escorts to attack the main station. Which, er, is obviously something all script makers have wanted to do since, like, forever. The fun part here is that it’s calling a custom method on the escorts’ scripts, with no specific support from Oolite.
Log chatter:
Escort script:
There are several bugs, including a confusing potential crasher, but the basic mechanism works.
I’ve also put up some documentation on the Script class.
Log chatter:
Mothership script:[scriptTest.mothership]: Telling 3 escorts to attack <StationEntity Coriolis Station 105>.
[scriptTest.escort]: Receiving orders from mothership - attacking <StationEntity Coriolis Station 105>!
[scriptTest.escort]: Receiving orders from mothership - attacking <StationEntity Coriolis Station 105>!
[scriptTest.escort]: Receiving orders from mothership - attacking <StationEntity Coriolis Station 105>!
Code: Select all
this.beingAttacked = function()
{
var escorts = this.ship.escorts;
if (escorts)
{
LogWithClass("scriptTest.mothership", "Telling " + escorts.length + " escorts to attack " + system.mainStation + ".");
function callEscortMethod(escort)
{
escort.script.scriptTestEscortAttack(system.mainStation);
}
escorts.forEach(callEscortMethod, this);
}
else
{
LogWithClass("scriptTest.mothership", "No escorts for me.");
}
}
Code: Select all
this.scriptTestEscortAttack = function(target)
{
// Method to be called by mothership script
LogWithClass("scriptTest.escort", "Receiving orders from mothership - attacking " + target + "!");
this.ship.target = target;
this.ship.setAI("interceptAI.plist");
}
I’ve also put up some documentation on the Script class.