Page 1 of 1

Help with newbie tinkering

Posted: Thu Jul 09, 2009 2:21 pm
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

Posted: Thu Jul 09, 2009 2:31 pm
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.

Posted: Thu Jul 09, 2009 2:43 pm
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!

Posted: Thu Jul 09, 2009 2:52 pm
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.

Posted: Thu Jul 09, 2009 3:03 pm
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....