I am overhauling Anarchies for Oolite 1.72, an also took the opportunity to add/change some features. One of them is that the Hacker Outpost is now spawn via the Henchman's ship-script.
Works fine. But then I thought: I actually generate two henchmen in each Anarchy system with TL >= 7, one on the witchpoint-planet route, one on the witchpoint-sun route, so the player can encounter them and therefore create an Outpost, regardless whether he goes to the station or sun-skimming. NOw I thought, of course it's possible that the player flies around a little more, and eventually meets both henchmen, resulting in two Hacker Outposts being created (possibly in the same place). Not good.
Fortunately there is the new remove() function, so I thought, why not removing the other henchman in the ship-script, right after spawning the Outpost? Said and done. Here's the code:
Code: Select all
this.removeOtherHenchman = function()
{
// create an array of both henchmen in the system
this.allHenchmen = system.shipsWithPrimaryRole("anarchies_henchman", this.ship);
// remove the last one (which is not the calling)
log("Anarchies", this.allHenchmen[1])
this.allHenchmen[1].remove()
}
Except it doesn't work. I always get
But now comes the really strange part. I didn't encounter the problem while testing it by spawning a henchman with the Debug-menu. Only with the ones spawned by script.[script.javaScript.warning.162]: ----- JavaScript warning: reference to undefined property this.allHenchmen[1]
[script.javaScript.warning.162]: /Applications/Spiele/Oolite 1.72/AddOns/Anarchies1.1.oxp/Scripts/anarchies-henchman-script.js, line 65.
[script.javaScript.exception.39]: ***** JavaScript exception: TypeError: this.allHenchmen[1] has no properties
[script.javaScript.exception.39]: /Applications/Spiele/Oolite 1.72/AddOns/Anarchies1.1.oxp/Scripts/anarchies-henchman-script.js, line 65.
I repeat: If I spawn a henchman via Debug-menu/JS-console, everything works fine. He scans for me, finds me, spawns the Hacker Outpost, searches for other henchmen in the system, lists them correctly in the this.allHenchmen-array, and removes the second entry from the array. Everything's fine.
But if I meet one of the henchmen spawned by script, he scans for me, finds me, spawns the Hacker Outpost, searches for other other henchmen in the system (I hope), but then Oolite insists that the this.allHenchmen-array doesn't exists, or has no properties.
I am completely puzzled. If I examine and compare a henchman spawned by script and one spawned by using the JS-console, I can discover to difference between them whatsoever. So what's the problem? Why does it work in one case, and doesn't in the other?
Help!
PS: When my console-created test-henchman successfully eliminates one of the other henchmen in-system, I get this in the log:
Does that help somehow?[method.undead]: Believed-dead method -[ShipEntity setSuppressExplosion:] called.
PPS: And I do get the same error message, if I console-create a henchman in a system where there are no other henchmen. But that can't be the culprit with the script-created henchmen, because there are always two of them. And I can find and eliminate them perfectly, if I just type the same code I use in the script directly in the console-window. I am really puzzled.