Hi all,
I modified my copy of the [wiki]Imperial Star Destroyer[/wiki]. I gave it 4 Thargoid Lasers, made it much more robust and less agile and so on
I am now also trying to give the Star Destroyer a chance of becoming a big explosion when it get's destroyed, by placing a Q-Bomb (or more precisely: a ship with role "energy-bomb") at it's last position. But the Q-Bomb I add doesn't detonate, although my Q-Mine-Detector raises an alarm. So I thought to myself "
hmm, maybe the Q-Bomb gets instantly destroyed by the explosion of the Star Destroyer?
Let's add it after a short delay, so the explosion has run off!"
But placing a timer inside the script for the Star Destroyer (I called it's
this.name = "stardestroyer"
) didn't work, so I thought that is because the ship is destroyed and with it the timer get's removed.
So I changed the code and moved the timing functionality into a new world script (
this.name = "stardestroyer_worldscript"
. I wanted to add only a single function, so I made it that the Timer calls the same function that created him again, but with a different parameter. Here is the code:
stardestroyer, which is the
script = "stardestroyer.js"
from shipdata.plist:
Code: Select all
this.name = "stardestroyer";
this.author = "GGShinobi";
this.copyright = "© 2013 GGShinobi, Creative Commons: attribution, non-commercial, sharealike.";
this.description = "some special actions for the stardestroyer.";
this.version = "0.0.0";
"use strict";
this.shipDied = function(whom, why) {
// if (Math.random() > 0.77) {
worldScripts.stardestroyer_worldscript.$starDestroyer_BigBang(this.ship.position, 5); //3.33);
// }
}
Note that this calls "$starDestroyer_BigBang" with
countdown = 5.
stardestroyer_worldscript:
Code: Select all
this.name = "stardestroyer_worldscript";
this.author = "GGShinobi";
this.copyright = "© 2013 GGShinobi, Creative Commons: attribution, non-commercial, sharealike.";
this.description = "some special actions for the stardestroyer.";
this.version = "0.0.0";
"use strict";
this.$selfDestructCountdown;
this.$starDestroyer_BigBang = function(position, countdown) {
log("Star Destroyer", "starDestroyer_BigBang called: position" + position + " / countdown: " + countdown);
if (countdown > 0) {
player.commsMessage("detonation in " + countdown + " seconds!");
this.$selfDestructCountdown = new Timer(this, $starDestroyer_BigBang(position, 0), countdown);
} else {
player.commsMessage("Warning! Explosion detected!");
system.addShips("energy-bomb", 1, position, 0);
// system.addShips("EQ_QC_MINE", 1, this.ship.position, 0);
this.$selfDestructCountdown.stop(); this.$selfDestructCountdown.delete();
}
}
Note that this creates a timer which is supposed to call "$starDestroyer_BigBang" again after 5 seconds (countdown), but this time with
countdown = 0!
But, from my logfiles I get this:
Code: Select all
05:58:22.015 [Star Destroyer]: starDestroyer_BigBang called: position(39892, -85261.1, 456021) / countdown: 5
05:58:22.015 [Star Destroyer]: starDestroyer_BigBang called: position(39892, -85261.1, 456021) / countdown: 0
05:58:22.033 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (stardestroyer 0.0.0): TypeError: this.$selfDestructCountdown is undefined
05:58:22.033 [script.javaScript.exception.unexpectedType]: /home/ggshinobi/.Oolite/AddOns/stardestroyerV1.3.oxp/Scripts/stardestroyer_worldscript.js, line 18.
As you can see, the second call to "$starDestroyer_BigBang", which I intended to be made after a delay of 5 seconds, is instead be done instantly, when the Timer is created!
Is this behaviour intentionally or a bug? I thought the function call that is given as parameter to the timer is called for the first time
after the delay has passed...
Also, did you notice any other errors or wrong assumptions I've made?
What I'm gonna test next is if it works when I move the timer creation to another function.