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

guiScreenChanged not working?

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

Moderators: winston, another_commander, Getafix

User avatar
Nemoricus
---- E L I T E ----
---- E L I T E ----
Posts: 388
Joined: Mon May 18, 2009 8:51 pm

guiScreenChanged not working?

Post by Nemoricus »

I'm writing a script that uses this.guiScreenChanged = function (to) and Oolite is not recognizing it as a function.

Is this something that I'm doing wrong, or is there a problem with Oolite 1.72.2 with that event handler?

Error log:

Code: Select all

[script.javaScript.exception.22]: ***** JavaScript exception: TypeError: this.guiScreenChanged is not a function
[script.javaScript.exception.22]:       AddOns/Galactic_Navy.oxp/Scripts/galnavymain.js, line 201.
[script.javaScript.load.failed]: ***** Error loading JavaScript script AddOns/Galactic_Navy.oxp/Scripts/galnavymain.js -- could not run script
[script.load.notFound]: ***** Could not find a valid script file named galnavymain.js.
My code:

Code: Select all

//Brings up appropriate screens after the mission screen ends.
this.guiScreenChanged = function(to)
{
	if(missionVariables.navy_officer == "SCOOPED")
		this.OfficerRescueReward();

	if(player.ship.dockedStation.name == "Navy SecCom Station")
		this.SecComBusiness();
}
Dream as if you'll live forever
Live as if you'll die tomorrow
User avatar
Frame
---- E L I T E ----
---- E L I T E ----
Posts: 1477
Joined: Fri Mar 30, 2007 8:32 am
Location: Witchspace

Post by Frame »

you got some basic errors there... none of them reveal though, why it is not accepting that as a function.. I'm not even sure you need (to) We need to see the entire script file..

but to point out...

your code

Code: Select all

if(player.ship.dockedStation.name == "Navy SecCom Station") 
Will generate an error when the player is not docked... because dockedStation will be Null, and then you effectively call a property of null which is illegal and will generate an Exception.

you need to do it like this

Code: Select all

if(player.ship.docked) //we check first for if the player is docked...
{
   if(player.ship.dockedStation.name == "Navy SecCom Station")
   this.SecComBusiness(); 
}
Ahh i just figured out what you did wrong... you have this.guiScreenChanged() put inside another function.. it means the function is never declared thus unknown to the system, or as it writes, not a function. Still we need the entire script...I'm not even sure you are pasting the correct lines from where to error originates... as you should have just declared that funtion, inside another according to what you pasted.. however.. you still need to show us the entire script file.
Bounty Scanner
Number 935
User avatar
Nemoricus
---- E L I T E ----
---- E L I T E ----
Posts: 388
Joined: Mon May 18, 2009 8:51 pm

Post by Nemoricus »

Okay, I have to admit that I'm not quite sure what you're trying to say.

I need to have it so that it checks if the player is docked for both function calls. I didn't notice that until after you mentioned the docking bit.

However, this.guiScreenChanged = function(to){} is as the wiki has it. I also know that it's this line that's generating the error as that's the only time I'm using that event handler.

Here's the whole script.
Dream as if you'll live forever
Live as if you'll die tomorrow
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: guiScreenChanged not working?

Post by Eric Walch »

Nemoricus wrote:
I'm writing a script that uses this.guiScreenChanged = function (to) and Oolite is not recognizing it as a function.
Your code as listed is correct. I use in my script for some time:

Code: Select all

this.guiScreenChanged = function(newScreen, oldScreen)
{
	if(oldScreen == "GUI_SCREEN_REPORT") this.ups_missionOffers();
}
without any problems. It is even used in one of oolites own internal missions (Constrictor Hunt.js)
User avatar
Nemoricus
---- E L I T E ----
---- E L I T E ----
Posts: 388
Joined: Mon May 18, 2009 8:51 pm

Post by Nemoricus »

Interesting. I didn't change anything and it seems to be working just fine now. Of course, I found another error in my script, but it's unrelated.

Thanks, both of you.
Dream as if you'll live forever
Live as if you'll die tomorrow
User avatar
CaptKev
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Fri Jan 26, 2007 3:21 pm
Location: Shropshire, UK

Post by CaptKev »

Image

I'm using the code below to produce the system data screen like the one above whenever a different system is selected in the long or short range charts.

The only problem is the planet texture doesn't refresh until I reselect the system data screen again.

Does anyone know of a way around this problem?

Code: Select all

this.guiScreenChanged = function(toGUI, fromGUI) {

	if (toGUI == 'GUI_SCREEN_SYSTEM_DATA') {

		if (!system.infoForSystem(galaxyNumber, player.ship.targetSystem).texture) {

			system.infoForSystem(galaxyNumber, player.ship.targetSystem).texture = 'home_planet' + (((this.system_info[galaxyNumber * 256 + player.ship.targetSystem] & 0x3F000) >> 12) + 1) + '.png';
		}
		var sInhabitants = system.infoForSystem(galaxyNumber, player.ship.targetSystem).inhabitants;
		var aInhabitants = sInhabitants.split(" ");
		setScreenOverlay(aInhabitants[(aInhabitants.length - 1)] + ".png");
	}
}
Download Fighter HUD, Stingray and System Redux from the EliteWiki
User avatar
DaddyHoggy
Intergalactic Spam Assassin
Intergalactic Spam Assassin
Posts: 8512
Joined: Tue Dec 05, 2006 9:43 pm
Location: Newbury, UK
Contact:

Post by DaddyHoggy »

Can't help with a fix, but your frog doesn't look very blue (or does the description refer to their state-of-mind and general outlook on life?) :wink:
Selezen wrote:
Apparently I was having a DaddyHoggy moment.
Oolite Life is now revealed here
User avatar
Cmdr Wyvern
---- E L I T E ----
---- E L I T E ----
Posts: 1649
Joined: Tue Apr 11, 2006 1:47 am
Location: Somewhere in the great starry void

Post by Cmdr Wyvern »

DaddyHoggy wrote:
Can't help with a fix, but your frog doesn't look very blue (or does the description refer to their state-of-mind and general outlook on life?) :wink:
Said frog doesn't look very cheerful. Maybe that's where the "blue" comes from.
And he's donning a rather primitive dress. I would think they'd trade in the leather loincloths for suits on a TL 14, rich industrial corporate state.
Running Oolite buttery smooth & rock stable w/ tons of eyecandy oxps on:
ASUS Prime X370-A
Ryzen 5 1500X
16GB DDR4 3200MHZ
128GB NVMe M.2 SSD (Boot drive)
1TB Hybrid HDD (For software and games)
EVGA GTX-1070 SC
1080P Samsung large screen monitor
User avatar
CaptKev
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Fri Jan 26, 2007 3:21 pm
Location: Shropshire, UK

Post by CaptKev »

:D

I only have eight different images at the moment (Birds, Colonials, Felines, Frogs, Insects, Lizards, Lobsters and Rodents).
Download Fighter HUD, Stingray and System Redux from the EliteWiki
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5525
Joined: Thu Jun 12, 2008 6:55 pm

Post by Thargoid »

To go back to the original question - I'm not sure that there is a way at the moment. There is this.guiScreenWillChange(to, from), but that only fires for selected gui screens (not including the system data one).

Perhaps it may be worth requesting that function triggers for all screens, or at least for this one?
User avatar
Cmd. Cheyd
---- E L I T E ----
---- E L I T E ----
Posts: 934
Joined: Tue Dec 16, 2008 2:52 pm
Location: Deep Horizon Industries Manufacturing & Research Site somewhere in G8...

Post by Cmd. Cheyd »

LOL. I'd been working on a similar function for my OXP, Capt. Kev. Ran into the same issue, then shelved it for the time being.
User avatar
CaptKev
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Fri Jan 26, 2007 3:21 pm
Location: Shropshire, UK

Post by CaptKev »

@Thargoid, thanks for the info. I did try guiScreenWillChange(), now I know why it didn't work.

@Cmd. Cheyd, maybe if we both ask the Dev's really nicely
Download Fighter HUD, Stingray and System Redux from the EliteWiki
User avatar
CaptKev
---- E L I T E ----
---- E L I T E ----
Posts: 519
Joined: Fri Jan 26, 2007 3:21 pm
Location: Shropshire, UK

Post by CaptKev »

Cmdr Wyvern wrote:
DaddyHoggy wrote:
Can't help with a fix, but your frog doesn't look very blue (or does the description refer to their state-of-mind and general outlook on life?) :wink:
Said frog doesn't look very cheerful. Maybe that's where the "blue" comes from.
And he's donning a rather primitive dress. I would think they'd trade in the leather loincloths for suits on a TL 14, rich industrial corporate state.
Not just a suit a space suit
Image
Download Fighter HUD, Stingray and System Redux from the EliteWiki
User avatar
caracal
Deadly
Deadly
Posts: 205
Joined: Wed Jun 25, 2008 11:31 am
Location: The Desert, USA
Contact:

Post by caracal »

CaptKev wrote:
Cmdr Wyvern wrote:
DaddyHoggy wrote:
Can't help with a fix, but your frog doesn't look very blue (or does the description refer to their state-of-mind and general outlook on life?) :wink:
Said frog doesn't look very cheerful. Maybe that's where the "blue" comes from.
And he's donning a rather primitive dress. I would think they'd trade in the leather loincloths for suits on a TL 14, rich industrial corporate state.
Not just a suit a space suit
Okay, this is freakin' gorgeous, CaptKev! Will have me straying to the F7 screen a lot more often once you release, and planet textures be hanged. I only care about those when I'm actually orbiting the planet anyway.
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6569
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

As of revision 3734, guiScreenWillChange is fired also just before switching to planet info screen.

Now bring the nice pics on!
Post Reply