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

Help with newbie tinkering

Discussion and information relevant to creating special missions, new ships, skins etc.

Moderators: winston, another_commander

Post Reply
Flashheart
Above Average
Above Average
Posts: 23
Joined: Tue Jun 30, 2009 2:15 pm
Location: Staffordshire, England

Help with newbie tinkering

Post by Flashheart »

Say I want to add a 'farewell message' each time I depart a station. According to the Wiki this should work if save in C:\Program Files\Oolite\AddOns\flashheart.oxp\Config\ as script.js

Code: Select all

this.name = "ByeBye";
this.author	= "FlashHeart";
this.description = "Farewell messages from stations";
this.version = "1.0";
this.copyright = "This work is hereby placed in the public domain.";

/*  You can copy and paste this function and just change the "startUp"
    to another event name to handle other OXP events (eg "STATUS_DOCKED",
    "alertConditionChanged", etc).
*/
this.startUp = function()
{
    Log("Initialising OXP " + name);
}

this.shipLaunchedFromStation = function()
{
    this.consoleMessage("Thanks for dropping by, have fun out there!", 5);
}
...but it doesn't seem to. Or am I missing something really basic? Am I supposed to tell oolite somewhere else to look for this script?

TIA :D
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6568
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

If you look at your Latest.log, you will find this:

Code: Select all

[script.javaScript.exception.1]: ***** JavaScript exception: ReferenceError: name is not defined
[script.javaScript.exception.1]:       AddOns/scripttest.oxp/script.js, line 13.
Oolite is usually giving good hints as to what went wrong inside Latest.log. Based on the above, we can correct line 13 to

Code: Select all

Log("Initialising OXP " + this.name); 
Now Oolite will complain with

Code: Select all

[script.javaScript.exception.22]: ***** JavaScript exception: TypeError: this.consoleMessage is not a function
[script.javaScript.exception.22]:       AddOns/scripttest.oxp/script.js, line 18.
This error means that there is no such thing as this.consoleMessage. consoleMessage is a player method.

So, the final correct script should be this:

Code: Select all

this.name = "ByeBye"; 
this.author   = "FlashHeart"; 
this.description = "Farewell messages from stations"; 
this.version = "1.0"; 
this.copyright = "This work is hereby placed in the public domain."; 

/*  You can copy and paste this function and just change the "startUp" 
    to another event name to handle other OXP events (eg "STATUS_DOCKED", 
    "alertConditionChanged", etc). 
*/ 
this.startUp = function() 
{ 
    log("Initialising OXP " + this.name); 
} 

this.shipLaunchedFromStation = function() 
{ 
    player.consoleMessage("Thanks for dropping by, have fun out there!", 5); 
} 
This works and the message pops up. Just be sure to press Shift when restarting Oolite after you have applied the change.
Flashheart
Above Average
Above Average
Posts: 23
Joined: Tue Jun 30, 2009 2:15 pm
Location: Staffordshire, England

Post by Flashheart »

Okeedokey! Thanks for that, didn't know about Latest.log.

I pasted the first bit from the template on the wiki...

Code: Select all

Log("Initialising OXP " + name); 
Silly me forgot that 'player' was the object
:oops:
Just be sure to press Shift when restarting Oolite after you have applied the change.
Why, what does that do?


Not too familiar with javascript but ok with Pascal/C/Basic etc....how hard can it be? :lol:

Now I shall have some fun and probably break some things in the process :D

Many thanks!
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6568
Joined: Wed Feb 28, 2007 7:54 am

Post by another_commander »

Flashheart wrote:
Just be sure to press Shift when restarting Oolite after you have applied the change.
Why, what does that do?
Oolite is caching information from OXPs and its own Resources folder for performance reasons. This cache is refreshed automatically when a new oxp is added or an existing oxp gets removed. But if you just change the contents of a file inside an oxp folder, the game will not be able to see that change and continue using its previously cached information, giving you the impression that it does not recognize your changes. Many newcomers have fallen victim to this. To ensure that the cache is rebuilt with the contents of your changes included, you will need to hold down Shift while launching Oolite until you see the Cobra rotating.
Flashheart
Above Average
Above Average
Posts: 23
Joined: Tue Jun 30, 2009 2:15 pm
Location: Staffordshire, England

Post by Flashheart »

Ok - I tried it anyway, it worked fine :)

Now, I still see the 'Forward View' message on launching. I thought this might be the default message for the shipLaunchedFromStation method but I guess it must be the after-tunnel-effect or whatever it's called or maybe just hard-coded..... tinkering more....
Post Reply