Page 1 of 1

Mission variables

Posted: Mon Nov 15, 2010 5:02 pm
by Mauiby de Fug
I'm dabbling about in writing my own oxps now, or at least, trying to familiarize myself with the way that Oolite works.

From what I can tell, the only way to get a variable that lasts longer after Oolite shuts down is to save it as a mission variable in the save game.

I may be being rather dense, but I can't work out how to create one. I've trawled through the wiki pages, and had a nosey in the other oxps on my computer, but my poor brain's beginning to melt. I've probably seen it half a dozen times by now, but I haven't yet recognised it or been able to reproduce it.

Can anyone tell me how to create one? Or give me an example where upon docking at, say, "My new Station", it saves a variable saying "HAS DOCKED"?

I eventually managed to create a station today. There's something very satisfying about telling it to spawn in the console and seeing it appear in nearby space, and having something come up in the Advanced Space Compass! Even if it looks identical to a lowly Rock Hermit! And especially after one spent over an hour trying to work out why one's supposedly perfectly valid code refused to parse, and the problem is finally solved by copying and pasting it a few lines at a time until one finds the lack of a / in an </key>!

(Mastering Wings to get something that looks useable is proving tricky at the moment, so I'm persevering and dabbling in the scripting side of things while I get to grips with it!)

Posted: Mon Nov 15, 2010 6:01 pm
by Kaks
In javascript, from the console:

Code: Select all

missionVariables.testing='yep,testing';
Save your game, close Oolite.
Restart Oolite, load your game, type

Code: Select all

missionVariables.testing
the console should display

yep,testing


Did you read the following page?

http://wiki.alioth.net/index.php/Oolite ... ce:_Global

Posted: Mon Nov 15, 2010 6:10 pm
by Mauiby de Fug
Aha! It worked! Now to get the hang of event handling!

And no, I hadn't found that page, alas. If only I'd found that one instead of the other or so that I've got open in my browser...

Thanks for the info!

Posted: Mon Nov 15, 2010 6:31 pm
by Thargoid
If you're embarking on the road to OXP scripting wisdom (or madness), it's worth consuming, digesting and cogitating all of the Javascript reference pages on the wiki.

Also learning golden rule 1b - for OXPs it's a good habit to get into to make all OXP-specific things such as mission variables, unique roles, ship identifiers and so forth unique by sticking either your name or the name of your OXP in front of them (see most published OXPs for examples). It just saves future clash risks from using generic names (having two OXPs sharing the same MV for example, and one changing things and screwing up the other).

Posted: Mon Nov 15, 2010 6:40 pm
by Mauiby de Fug
Thargoid wrote:
If you're embarking on the road to OXP scripting wisdom (or madness), it's worth consuming, digesting and cogitating all of the Javascript reference pages on the wiki.
I had a look through a whole bunch of them; that one must have slipped me by...
Thargoid wrote:
Also learning golden rule 1b - for OXPs it's a good habit to get into to make all OXP-specific things such as mission variables, unique roles, ship identifiers and so forth unique by sticking either your name or the name of your OXP in front of them (see most published OXPs for examples). It just saves future clash risks from using generic names (having two OXPs sharing the same MV for example, and one changing things and screwing up the other).
I was doing that already, having noticed the numerous warnings about it posted all over the forums, and seeing the way things are labelled in both the oxps and the savegames! 'Tis a most sensible convention!