ship script event handlers confusion

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:

ship script event handlers confusion

Post by Commander McLane »

What is the difference between the ship script event handlers shipWillEnterWitchspace and playerWillEnterWitchspace?

I was under the impression that shipWillEnterWitchspace would trigger when the NPC itself jumps out, while playerWillEnterWitchspace would trigger when the player jumps out. Apparently I am mistaken, at least for current trunk. I think it was working this way a few versions back, or at least I always assumed that this was the case.

Or has shipWillEnterWitchspace been deprecated?

What I expected shipWillEnterWitchspace would do, is actually done by shipWillEnterWormhole. (I just noticed that a personality still broadcast messages after jumping out. Only this way I found out that the broadcast timer isn't removed on shipWillEnterWitchspace. I haven't witnessed that before, but it also may be that I just didn't hang around after a personality jumped out.)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: ship script event handlers confusion

Post by JensAyton »

shipWillEnterWitchspace() is sent to world scripts/player ship script and tells you the context of the jump. playerWillEnterWitchspace() is sent to NPC ships, later in the process (about as late as possible).

There doesn’t seem to be a good reason for this.
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: ship script event handlers confusion

Post by Eric Walch »

Commander McLane wrote:
Or has shipWillEnterWitchspace been deprecated?
It has never been there in the first place. It has always been a player-only thing. The two wiki handler pages used to be one. Kaks has split them in two separate pages a year ago. But some handlers stayed in both pages. I thought I deleted some of there bugs, but apparently not all. shipWillEnterWitchspace will only be send to worldScripts and has never been send to ship scripts.
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:

Re: ship script event handlers confusion

Post by Commander McLane »

Eric Walch wrote:
Commander McLane wrote:
Or has shipWillEnterWitchspace been deprecated?
It has never been there in the first place. It has always been a player-only thing.
Thanks for the clarification. Apparently I always only assumed/imagined that it was working the way I wanted to. :? Will have to hunt for wrong use in other ship scripts as well.
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: ship script event handlers confusion

Post by Kaks »

Hmm, unfortunately I didn't manage as clean a cut between the ship & world events - on the wiki - as I would have liked.

As why there are 2 js events for just one Oolite event, one with & one without parameters, it's indeed a mystery - an API bug if you will. I'd deprecate the slightly confusing shipWillEnterWitchspace, and use playerWillEnterWitchspace, making sure it sends the context of the jump.
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: ship script event handlers confusion

Post by JensAyton »

Kaks wrote:
As why there are 2 js events for just one Oolite event, one with & one without parameters, it's indeed a mystery - an API bug if you will. I'd deprecate the slightly confusing shipWillEnterWitchspace, and use playerWillEnterWitchspace, making sure it sends the context of the jump.
Too late! (Actually, the Right Thing here would be to rename NPC shipWillEnterWormhole to shipWillEnterWitchspace for consistency, but I ain’t doing that now either. The scripting interface is frozen, not mildly chilled.)
User avatar
Kaks
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 3009
Joined: Mon Jan 21, 2008 11:41 pm
Location: The Big Smoke

Re: ship script event handlers confusion

Post by Kaks »

Meh, hence I said 'an API bug, if you will' above! :P

If we reclassify 'confusing inconsistency' as 'breakage', we get enough wiggle room to fix it even at -272.5 deg. C! ;)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
Post Reply