Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

runScreen not always firing when expected to

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

Moderators: winston, another_commander, Getafix

Switeck
---- E L I T E ----
---- E L I T E ----
Posts: 2411
Joined: Mon May 31, 2010 11:11 pm

Re: runScreen not always firing when expected to

Post by Switeck »

I only offered the code example because for the simple case of showing the mission briefing...it works. :P
User avatar
Capt. Murphy
Commodore
Commodore
Posts: 1127
Joined: Fri Feb 25, 2011 8:46 am
Location: UK South Coast.

Re: runScreen not always firing when expected to

Post by Capt. Murphy »

Why don't you let this.missionScreenOpportunity deal with potential conflicts? Anywhere you want to runScreen, set a flag, and manually call this.missionScreenOpportunity().

Under the event handler function include a condition check for the flag and if met the appropriate runScreen command. It is easy this way to look after multiple screens, daisy chain screens etc. Take a look at the current Explorers' Club to see how the options and associated screens are set up.
[EliteWiki] Capt. Murphy's OXPs
External JavaScript resources - W3Schools & Mozilla Developer Network
Win 7 64bit, Intel Core i5 with HD3000 (driver rev. 8.15.10.2696 - March 2012), Oolite 1.76.1
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: runScreen not always firing when expected to

Post by Eric Walch »

PhantorGorth wrote:
Eric Walch wrote:
The 'to' in guiScreenChanged() is often a bit of useless in my opinion. In most cases you don't want to know were the original code changed to, but you want to know the page you are currently viewing.
It isn't useless if you are launching a mission screen when you go from one particular screen to another particular screen. This is done for my Triple-F5 screen I use in my Visas WIP.
I disagree here. Specially when you use it for showing a missionscreen, or adding text to the current screen it is useless. It is not guaranteed that the 'to' screen is the current screen, so you must test for the current screen instead of the 'to' screen. When no other oxp het interacted during this handler, both screens still will be the same.

The only time when you can use the 'to' is when just setting a few variables on the action and you are not interested in the actual current screen.
User avatar
PhantorGorth
---- E L I T E ----
---- E L I T E ----
Posts: 647
Joined: Wed May 20, 2009 6:48 pm
Location: Somewhere off the top left of Galaxy 1 map

Re: runScreen not always firing when expected to

Post by PhantorGorth »

Capt. Murphy wrote:
Why don't you let this.missionScreenOpportunity deal with potential conflicts? Anywhere you want to runScreen, set a flag, and manually call this.missionScreenOpportunity().

Under the event handler function include a condition check for the flag and if met the appropriate runScreen command. It is easy this way to look after multiple screens, daisy chain screens etc. Take a look at the current Explorers' Club to see how the options and associated screens are set up.
I am considering this. :-)
Chat and relax with other commanders in the [url=irc://irc.oftc.net/oolite]DS's Seedy Space Bar[/url]. The Coolest Bar in the Eight.

Phantor's OXPs: [EliteWiki] GalCop Rewards and [EliteWiki] Safe Docking
User avatar
PhantorGorth
---- E L I T E ----
---- E L I T E ----
Posts: 647
Joined: Wed May 20, 2009 6:48 pm
Location: Somewhere off the top left of Galaxy 1 map

Re: runScreen not always firing when expected to

Post by PhantorGorth »

Eric Walch wrote:
PhantorGorth wrote:
Eric Walch wrote:
The 'to' in guiScreenChanged() is often a bit of useless in my opinion. In most cases you don't want to know were the original code changed to, but you want to know the page you are currently viewing.
It isn't useless if you are launching a mission screen when you go from one particular screen to another particular screen. This is done for my Triple-F5 screen I use in my Visas WIP.
I disagree here. Specially when you use it for showing a missionscreen, or adding text to the current screen it is useless. It is not guaranteed that the 'to' screen is the current screen, so you must test for the current screen instead of the 'to' screen. When no other oxp het interacted during this handler, both screens still will be the same.

The only time when you can use the 'to' is when just setting a few variables on the action and you are not interested in the actual current screen.
The circumstances I am referring to are not about knowing the current screen but about the one you will be going to, to intercept. My Visas' Triple-F5 screen is a mission screen acting as a gui screen to provide information about the Visas you own. It is accessed by pressing F5 on the Manifest screen. Under normal circumstances the screen then displayed is the Status screen but on guiChangeScreen event I use the fact that "from" is GUI_SCREEN_MANIFEST and "to" is GUI_SCREEN_STATUS to launch my mission screen. It doesn't matter which screen the current actually is at that moment just that the screen it's going to is meant to be GUI_SCREEN_STATUS and you are coming from is GUI_SCREEN_MANIFEST. This is purely about navigation of screens, not what is displayed. The only proviso is to make sure that the current screen isn't another mission screen, which caused me a headache for my GalCop_Rewards OXP. When you press space on the Visas' mission screen the screen displayed should be, but doesn't necessarily need to be, the Status screen, but if it is, the navigation looks like I have added a screen to the F5 button cycle which is what I am after.
Chat and relax with other commanders in the [url=irc://irc.oftc.net/oolite]DS's Seedy Space Bar[/url]. The Coolest Bar in the Eight.

Phantor's OXPs: [EliteWiki] GalCop Rewards and [EliteWiki] Safe Docking
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: runScreen not always firing when expected to

Post by Commander McLane »

Thargoid wrote:
Also you seem to check if the player is docked after you've checked two examples of what the docked station will be? Either the check for player.ship.docked is superfluous, or one of the preceding two will fail badly as dockedStation won't have any properties (as you won't be docked). The order would be better with the dock check first (and in an if statement you don't need ==true, just player.ship.docked is sufficient, the check for true is implicit).
There should always be a check for player.ship.docked first. It's never superfluous. The reason is that it is possible to immediately re-launch the player by script upon docking. Scripts that check for a property of the docked entity (like isMainStation or another one) will throw an error, because dockedStation is already null and therefore has no properties. I'm just checking this situation of docking and immediate script-induced re-launch, and Snoopers is giving me this error every time:

Code: Select all

22:24:33.331 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (snoopers 2.1): TypeError: player.ship.dockedStation is null
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Re: runScreen not always firing when expected to

Post by Thargoid »

I meant where it is in the posted script it's superfluous (either the preceeding checks self-evidently prove that the player is docked, or the script will bomb out with precisely the kind of error you posted and will never get to the dock check anyway).

You are entirely correct though that the first check should always be that the player is docked. I was speaking specifically about this particular example, which indeed should be rearranged into the correct order.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: runScreen not always firing when expected to

Post by Svengali »

Commander McLane wrote:
There should always be a check for player.ship.docked first. It's never superfluous. The reason is that it is possible to immediately re-launch the player by script upon docking. Scripts that check for a property of the docked entity (like isMainStation or another one) will throw an error, because dockedStation is already null and therefore has no properties. I'm just checking this situation of docking and immediate script-induced re-launch, and Snoopers is giving me this error every time:

Code: Select all

22:24:33.331 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (snoopers 2.1): TypeError: player.ship.dockedStation is null
Sure - I'll add a check as it is a valid method and Oolite allows it.

But still - it smells like a problematic approach which might have other side-effects...
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: runScreen not always firing when expected to

Post by Kaks »

Hmm, there seems to be a few issues centred around scripts spitting out the player while they're docking.

There are some plans to overhaul the way docks work in the near-ish future, and including a way to totally prevent the player from docking might well become part of that overhaul... ;)
Hey, free OXPs: farsun v1.05 & tty v0.5! :0)
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

Re: runScreen not always firing when expected to

Post by Svengali »

Kaks wrote:
There are some plans to overhaul the way docks work in the near-ish future, and including a way to totally prevent the player from docking might well become part of that overhaul... ;)
OOoo .-)

And muchas gracias CMcL for the pointer .-)
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: runScreen not always firing when expected to

Post by Commander McLane »

Kaks wrote:
There are some plans to overhaul the way docks work in the near-ish future, and including a way to totally prevent the player from docking might well become part of that overhaul... ;)
That would be nice. :)
Svengali wrote:
And muchas gracias CMcL for the pointer .-)
You're welcome. :)
Post Reply