Page 1 of 2

Help required with js code

Posted: Sat Mar 19, 2011 11:57 am
by DGill
Could anyone help me with the appropriate script.

I don't understand js but can usually make do by copying other peoples code.


Image





I want to jump into a new galaxy, scoot across to a 'spy' who sends me an 'on-screen message' and also uploads instructions to my 'mission screen'.

I can get this to work reasonably well with the following code:



this.playerEnteredNewGalaxy = function()

{
...
system.legacy_addShipsAtPrecisely("bountyhunter", 1, "w", [0, 0, 0.3]);
mission.setInstructionsKey("mission_galaxy_instructgo");
...


which puts my bounty hunter at the waybeacon

and the code in the bountyhunter AI:


"FOUND_PLAYER" = ("commsMessage: [hunter-here]", "setAITo: exitingTraderAI.plist");

which displays an on-screen message.


The above works well, but i have my mission sceen updated with the message BEFORE I rendezvous with the bountyhunter.


What is the code for updating the mission screen only after I get in range of the bountyhunter, i.e the on-screen message and the mission screen instructions occur together.

Thanks

Re: Help required with js code

Posted: Sat Mar 19, 2011 12:09 pm
by Okti
Hi DGill,

Because you have the mission.setInstructionKey in the this.playerEnteredNewGalaxy event handler, the mission screen is updated when you enter the new galaxy.

You must work on a nother script block which will execute after player meets the bountyhunter.

Re: Help required with js code

Posted: Sat Mar 19, 2011 12:22 pm
by DGill
Okti wrote:
Hi DGill,

Because you have the mission.setInstructionKey in the this.playerEnteredNewGalaxy event handler, the mission screen is updated when you enter the new galaxy.

You must work on a nother script block which will execute after player meets the bountyhunter.
Any suggestion as to what the function call trigger would be?

this.playerEnteredNewGalaxy seems to be a valid call - what would be the event call for meeting another ship?

Re: Help required with js code

Posted: Sat Mar 19, 2011 12:38 pm
by Okti
DGill wrote:
Any suggestion as to what the function call trigger would be?

this.playerEnteredNewGalaxy seems to be a valid call - what would be the event call for meeting another ship?
What you need to do is atach a js file to your bountyhunter shipdata.plist entry And Have a code similar to that

Code: Select all

this.setMissionInstructions = function()
{
// do whatever you want
}
To call the function in JS change the line in the AI to the following

Code: Select all

"FOUND_PLAYER" = ("commsMessage: [hunter-here]","sendScriptMessage: setMissionInstructions", "setAITo: exitingTraderAI.plist");

Re: Help required with js code

Posted: Sat Mar 19, 2011 12:51 pm
by DGill
Thanks Okti, I'll give it a try

Re: Help required with js code

Posted: Sat Mar 19, 2011 12:53 pm
by Eric Walch
Just note that when setting instructions from other scripts than the worldScript, you must specify the worldScript when setting instructions, or the code does not know for which script the instructions are.

Code: Select all

this.setMissionInstructions = function()
{
// do whatever you want
mission.setInstructionsKey("mission_galaxy_instructgo", "your_worldscript_name");
}

Re: Help required with js code

Posted: Sat Mar 19, 2011 12:57 pm
by Okti
Eric Walch wrote:
Just note that when setting instructions from other scripts than the worldScript, you must specify the worldScript when setting instructions, or the code does not know for which script the instructions are.

Code: Select all

this.setMissionInstructions = function()
{
// do whatever you want
mission.setInstructionsKey("mission_galaxy_instructgo", "your_worldscript_name");
}
Thats right, I missed that. You must add a wordscripts.plist file to your Config directory pointing to js file. If necessary send a temprorary location to your OXP and I will test it, and point you to the right directions.

Re: Help required with js code

Posted: Sat Mar 19, 2011 9:47 pm
by Commander McLane
And note that what you are setting is not a mission screen, but the short mission description on the manifest screen. A mission screen is a different screen from the manifest screen.

Re: Help required with js code

Posted: Sat Mar 19, 2011 11:30 pm
by DGill
He he - it worked! - thanks guys

Only took 4 or 5 hours (and a bottle of wine) to do a couple of lines of code! really appreciate now those who write oxp from scratch.

Re: Help required with js code

Posted: Sat Mar 19, 2011 11:49 pm
by Commander McLane
DGill wrote:
He he - it worked! - thanks guys

Only took 4 or 5 hours (and a bottle of wine) to do a couple of lines of code! really appreciate now those who write oxp from scratch.
With time and practice you can certainly get it down to 2 or 3 hours, and half a bottle. :wink:

But seriously, it takes time indeed, and the actual creation of code takes the least of it. Firing up Oolite again and again, and testing whether it actually does what you want, then figuring out that you accidentally inserted (or left out) a semicolon or comma, correcting this, firing up Oolite again, only to discover the next small bug, etc., etc., is what actually makes up the lion's share of OXP-creating.

Re: Help required with js code

Posted: Sun Mar 20, 2011 12:53 am
by Mauiby de Fug
Commander McLane wrote:
Firing up Oolite again and again, and testing whether it actually does what you want, then figuring out that you accidentally inserted (or left out) a semicolon or comma, correcting this, firing up Oolite again, only to discover the next small bug, etc., etc., is what actually makes up the lion's share of OXP-creating.
This is the reason I haven't really got very far with my own efforts. I could probably find enough time to sit down and write things, if I didn't have to spend so much time booting up Oolite to find out what I did wrong.

Actually, thinking about it now, it's just occurred to me that when it comes to doing the same things repeatedly, I could probably write something to paste into the Debug console to do things automatically. Except that means getting more proficient with that... Still, might save me some time in the long run...

Re: Help required with js code

Posted: Sun Mar 20, 2011 9:20 am
by Thargoid
I recommend business trips for this - nice long evenings without much other commitment and a good way to avoid staring at hotel walls or at CNN. Oh and the supply of wine is better as well ;)

Re: Help required with js code

Posted: Sun Mar 20, 2011 11:12 am
by another_commander
Thargoid wrote:
I recommend business trips for this - nice long evenings without much other commitment and a good way to avoid staring at hotel walls or at CNN. Oh and the supply of wine is better as well ;)
Agree, but one has to be careful with that. I have often found myself in what started as nice long evenings without much commitment, fighting bugs (and I don't mean Thargoids here) until 03:30 in the morning, with an all-important meeting or presentation coming up at 08:00. It requires tremendous will power to be actually able to say 'I stop now' and stop, instead of 'I'll try this last thing, if it doesn't work I'm off to bed' over and over again.

Re: Help required with js code

Posted: Sun Mar 20, 2011 11:12 am
by JensAyton
Commander McLane wrote:
DGill wrote:
But seriously, it takes time indeed, and the actual creation of code takes the least of it. Firing up Oolite again and again, and testing whether it actually does what you want, then figuring out that you accidentally inserted (or left out) a semicolon or comma, correcting this, firing up Oolite again, only to discover the next small bug, etc., etc., is what actually makes up the lion's share of OXP-creating.
You can save a lot of time here using the console, especially for world scripts.

Code: Select all

> this.oxp = worldScripts["whatever"]
> oxp.doSomething = function () { stuff; }
If it spits out an error message, fix it and paste in the code again. If it works, you’ll get a copy of the code as a reply. Don’t forget to change oxp. to this. when pasting it back into the world script. When you’ve fixed the syntax errors, you can test it by calling oxp.doSomething() directly, or by triggering it through the game in the usual fashion.

On a Mac, you can make this simpler by pressing option-up-arrow or page up to get the previous input line back, and option-return to type a newline without sending it to the console. You can also make the text entry area bigger by dragging the separator.

Under Linux (and presumably Windows), you can’t copy from the console, so do all the editing in a text editor and copy each change over.
another_commander wrote:
It requires tremendous will power to be actually able to say 'I stop now' and stop, instead of 'I'll try this last thing, if it doesn't work I'm off to bed' over and over again.
I have no idea what you’re talking about.

<_<
>_>
<_<

What’s this “willpower” thing, then?

Re: Help required with js code

Posted: Sun Mar 20, 2011 11:14 am
by Eric Walch
Mauiby de Fug wrote:
Actually, thinking about it now, it's just occurred to me that when it comes to doing the same things repeatedly, I could probably write something to paste into the Debug console to do things automatically. Except that means getting more proficient with that... Still, might save me some time in the long run...
Yes, that works well when only changing small parts of the code. While Oolite is running, you can change the script, copy the changed function and paste it in the right way in the console. Works perfect for worldScripts and ship scripts. (Although you need to do it for every single ship you are examining, until you reboot Oolite)

Ninja, Ahruman already gave the answer in more depth. I only can add that for ship scripts, I target the ship and than use:

Code: Select all

this.oxp = PS.target.script
The other stuff goes as for worldScripts mentioned in the above message.