Help required with js code

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

Moderators: winston, another_commander

DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Help required with js code

Post 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
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Help required with js code

Post 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.
My OXP's
And Latest Mission Coyote's Run
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Help required with js code

Post 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?
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Help required with js code

Post 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");
My OXP's
And Latest Mission Coyote's Run
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Help required with js code

Post by DGill »

Thanks Okti, I'll give it a try
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Help required with js code

Post 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");
}
User avatar
Okti
---- E L I T E ----
---- E L I T E ----
Posts: 700
Joined: Sun Sep 26, 2010 1:51 pm
Location: A GH shop, near witchpoint to Oresrati in Galaxy 8

Re: Help required with js code

Post 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.
My OXP's
And Latest Mission Coyote's Run
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Help required with js code

Post 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.
DGill
---- E L I T E ----
---- E L I T E ----
Posts: 292
Joined: Thu Jan 01, 2009 9:45 am

Re: Help required with js code

Post 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.
User avatar
Commander McLane
---- E L I T E ----
---- E L I T E ----
Posts: 9520
Joined: Thu Dec 14, 2006 9:08 am
Location: a Hacker Outpost in a moderately remote area
Contact:

Re: Help required with js code

Post 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.
User avatar
Mauiby de Fug
---- E L I T E ----
---- E L I T E ----
Posts: 847
Joined: Tue Sep 07, 2010 2:23 pm

Re: Help required with js code

Post 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...
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Help required with js code

Post 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 ;)
another_commander
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 6671
Joined: Wed Feb 28, 2007 7:54 am

Re: Help required with js code

Post 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.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Help required with js code

Post 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?
User avatar
Eric Walch
Slightly Grand Rear Admiral
Slightly Grand Rear Admiral
Posts: 5536
Joined: Sat Jun 16, 2007 3:48 pm
Location: Netherlands

Re: Help required with js code

Post 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.
Post Reply