problem(?) with shipDockedWithStation event handler

For test results, bug reports, announcements of new builds etc.

Moderators: winston, another_commander, Getafix

Post Reply
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

problem(?) with shipDockedWithStation event handler

Post by Commander McLane »

With a lot of pushes (and help, especially from Eric) I have done it. I've taken my first steps in JS! :)

And now I've written my first very own small JS-script, translating the Thargoid Carrier's script into JS. It works (so far). :)

I have added something that was not there in the original script. If the player somehow has managed to dock with the Thargoid Carrier, he will be launched immediatly, at the end of the tunnel-effect (shipDockedWithStation-event), before even seeing the F5-screen.

Script looks like this:

Code: Select all

this.shipDockedWithStation = function()
{
	if (player.dockedStation.shipDescription == "Thargoid Carrier")
	{
		player.launch()
	}
}
It does what it is supposed to do. However, during playtesting I noticed this in my logfile:
[script.javaScript.exception.39]: ***** JavaScript exception: TypeError: player.dockedStation has no properties
[script.javaScript.exception.39]: /Applications/Spiele/Oolite 1.71.2/Oolite.app/Contents/Resources/Scripts/oolite-nova-mission.js, line 40.
Sometimes (obviously depending on the order in which the scripts are executed) also other scripts were mentioned with the same exception.

I guess it is caused by my Thargoid Carrier-script being executed before the other scripts (in this case the oolite-nova-mission script). So all the scripts are activated when I'm docking (to be precise: at the end of the tunnel-effect). The rest of the scripts (except mine) just find out that they have nothing to do on a Thargoid Carrier, and that's it. However, the oolite-nova-mission-script gets executed after my script. So at the time it runs, my ship has already been launched again, therefore I am no longer docked, therefore the exception. This is my interpretation.

My question is: Is this problematic? Can it be harmful in any way? At least a player, when looking into his logfile (or stderr), might think something is wrong here and send an error report, which I would like to avoid if possible.

EDIT: Oh, and once I also got this (unfortunately I forgot how). Anyway, nobody should accuse me of not following the polite request :wink: :
[general.error.inconsistentState]: ERROR: status is STATUS_DOCKED, but dockedStation is nil; treating as not docked. This is an internal error, please report it.
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: problem(?) with shipDockedWithStation event handler

Post by Eric Walch »

Commander McLane wrote:
Oh, and once I also got this (unfortunately I forgot how). Anyway, nobody should accuse me of not following the polite request :wink: :
[general.error.inconsistentState]: ERROR: status is STATUS_DOCKED, but dockedStation is nil; treating as not docked. This is an internal error, please report it.
This bug I already posted to Ahruman. I got it with the legacy script command launchFromStation that is in ThargoidWars. Apparently the js version does the same. It is launching the player but not setting the player status.
However, the oolite-nova-mission-script gets executed after my script. So at the time it runs, my ship has already been launched again, therefore I am no longer docked, therefore the exception. This is my interpretation.
Good analysis. I must have have the same bugs in UPS. I assume that when I am in the shipDockedWithStation event handled, I am really docked. But there could always have been a script sooner that forced it into launching again.

It is not a worse bug. Is will stop the handler from being executed any further. But the ship wasn't docked anymore at that time anyway.

There are two solutions to it: The scripters must add an extra test, for being docked. Or Oolite itself must stop proceeding with the docked event handlers when it gets a launch command.

EDIT:
When you want to avoid triggering the errors in some other scripts you could try moving the script from the main script to the carrier script. It will work from 1.71 onwards were the stations activate a handler when something is docking them.

Code: Select all

this.otherShipDocked = function(ship)
{
    if(ship.isPlayer) player.launch();
}
EDIT2:
It is not working with the launch() command. The handler is triggered at the beginning of the tunnel effect. The ship still docks in spite of the launch() command.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: problem(?) with shipDockedWithStation event handler

Post by JensAyton »

Eric Walch wrote:
There are two solutions to it: The scripters must add an extra test, for being docked. Or Oolite itself must stop proceeding with the docked event handlers when it gets a launch command.
I considered doing it the latter way but it turned out to be messy. I’m going to make do with adding if (player.docked) return; to the Nova script and recommending that anyone who relies on player.dockedStation do the same. Note that the docked station is passed as a parameter to the handler, so you can see what it was even if the player has already been launched:

Code: Select all

this.shipDockedWithStation = function (station) { ... }
Post Reply