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
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?
[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
[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.
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.
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.
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....