In one of my autojumper OXPs, I use an alloy "ship" to create a wormhole to a nearby system to force the player through:
Code: Select all
this.swi1 = system.addShips("alloy", 1, player.ship.position.add(player.ship.heading.multiply(270)), 0)[0]; // was distance 150
this.swi1.fuel = 7;
this.swi1.switchAI("missileAI.plist");
this.swi1.AIState ="EXPLODE";
this.swi1.exitSystem(i);
this.swi1.remove(true);
The alloy is spawned some 150-270 m(eters?) in front of the player's ship, so the wormhole is almost unavoidable if at full speed.
This...mostly...seems to work. If I remove the switchAI and EXPLODE ai state change, the alloy gets left in the destination systems despite the remove line...but that may not happen in v1.77 trunk betas due to change #4751: "- Don't disgorge and revive dead ships from wormholes."
http://svn.berlios.de/wsvn/oolite-linux ... 1&peg=4771
My problem arises with vaguely similar code in another OXP I'm working on. I'm wanting to assign a special ship/station to a variable and then check that variable for whether that ship exists. Here's the code I was trying:
Code: Select all
this.nullgate = system.legacy_addShipsAt("nullgate2", 1, "spu", [Math.random()*0.4-0.2, Math.random()*0.4-0.2, Math.random()*0.3+0.3]);
...
function nullgates_outboundNPCs(entity) {return entity.isShip && entity.AI == "exitingTraderAI.plist" && entity.AIState == "HEAD_AWAY_FROM_PLANET" && this.nullgate && entity.position.distanceTo(this.nullgate.position) < 300000};
...
if(this.nullgate) {
this.nullgate turns up as being undefined, so I can neither check for its existence nor move it.
I thought maybe the legacy_addShipsAt was to blame, so I converted it to using the newer addShips command:
Code: Select all
this.nullgate = system.addShips("nullgate", 1, Vector3D(Math.random()*0.4-0.2, Math.random()*0.4-0.2, Math.random()*0.3+0.3).fromCoordinateSystem("spu"))[0];
...
if(this.nullgate) {
Code: Select all
03:55:19.796 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (NullGate 0.8.14 - for Oolite 1.75 and later): TypeError: this.nullgate is undefined
03:55:19.796 [script.javaScript.exception.unexpectedType]: ../AddOns/NullGate v0.8.oxp/Scripts/nullgate.js, line 268.
if(this.nullgate) {
line.)Any ideas what I'm doing wrong?