Newbie help with Oolite Js API

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

Moderators: winston, another_commander

m4r35n357
---- E L I T E ----
---- E L I T E ----
Posts: 296
Joined: Wed Jan 19, 2011 4:00 pm

Re: Newbie help with Oolite Js API

Post by m4r35n357 »

Thargoid wrote:
A fairly simple example to review is the Cargo Shepherd I just released.

That scans for cargopods (by role and scanclass) and if it finds them it acts on them. And it's a very simple and small script. Have a look at that and see if it helps you.
OK will download & have a look, thanks.
User avatar
Thargoid
Thargoid
Thargoid
Posts: 5528
Joined: Thu Jun 12, 2008 6:55 pm

Re: Newbie help with Oolite Js API

Post by Thargoid »

I'm not sure you can pass a parameter directly on a timer call to a function. You may need to store it away in a script variable (this.something = whatever) and then refer to that in your called function.

I have a memory of having this issue myself in the past. My IronHide code you quoted is the callback function from a mission screen call, which is a slightly different case.
m4r35n357
---- E L I T E ----
---- E L I T E ----
Posts: 296
Joined: Wed Jan 19, 2011 4:00 pm

Re: Newbie help with Oolite Js API

Post by m4r35n357 »

Thargoid wrote:
I'm not sure you can pass a parameter directly on a timer call to a function. You may need to store it away in a script variable (this.something = whatever) and then refer to that in your called function.

I have a memory of having this issue myself in the past. My IronHide code you quoted is the callback function from a mission screen call, which is a slightly different case.
That sounds right to me, I'm looking at Cargo Shepherd right now, I hope that will clue me in on something I can use. Thanks, Ian.
m4r35n357
---- E L I T E ----
---- E L I T E ----
Posts: 296
Joined: Wed Jan 19, 2011 4:00 pm

Re: Newbie help with Oolite Js API

Post by m4r35n357 »

Ahruman wrote:
Fixed, download it again.
Edited requires.plist, now working, thanks.
m4r35n357
---- E L I T E ----
---- E L I T E ----
Posts: 296
Joined: Wed Jan 19, 2011 4:00 pm

Re: Newbie help with Oolite Js API

Post by m4r35n357 »

m4r35n357 wrote:
Thargoid wrote:
I'm not sure you can pass a parameter directly on a timer call to a function. You may need to store it away in a script variable (this.something = whatever) and then refer to that in your called function.

Yes, that is exactly how I am now using the timer, and it works! I need to check up on the precise semantics and timing(!) of the Timer, but basically I'm where I needed to be to proceed, so thanks to everyone who helped, Ian.
User avatar
JensAyton
Grand Admiral Emeritus
Grand Admiral Emeritus
Posts: 6657
Joined: Sat Apr 02, 2005 2:43 pm
Location: Sweden
Contact:

Re: Newbie help with Oolite Js API

Post by JensAyton »

Thargoid wrote:
I'm not sure you can pass a parameter directly on a timer call to a function.
You can’t, but you don’t need to, because JavaScript functions “close over” variables in their declared scope. For example:

Code: Select all

var x = 5;
this.t = new Timer(this, function() { log(x); }, 0); // Will log 5
Or, equivalently:

Code: Select all

function timerFunction(n)
{
    log(n);
}

var x = 5;
this.t = new Timer(this, function() { timerFunction(x); }, 0);
m4r35n357
---- E L I T E ----
---- E L I T E ----
Posts: 296
Joined: Wed Jan 19, 2011 4:00 pm

Re: Newbie help with Oolite Js API

Post by m4r35n357 »

I think the latter is what I want to do, eventually (I already have something that works so I will take a little time over it). Thanks for the tip.
m4r35n357
---- E L I T E ----
---- E L I T E ----
Posts: 296
Joined: Wed Jan 19, 2011 4:00 pm

Re: Newbie help with Oolite Js API

Post by m4r35n357 »

OK, it just worked first time, didn't even need variables, just passed literals to the "inner" function from the outer. Very nice Javascript lesson!
User avatar
TGHC
---- E L I T E ----
---- E L I T E ----
Posts: 2157
Joined: Mon Jan 31, 2005 4:16 pm
Location: Berkshire, UK

Re: Newbie help with Oolite Js API

Post by TGHC »

round of applause to everyone, more jelly babies.
The Grey Haired Commander has spoken!
OK so I'm a PC user - "you know whats scary? Out of billions of sperm I was the fastest"
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: Newbie help with Oolite Js API

Post by Okti »

TGHC wrote:
round of applause to everyone, more jelly babies.
:lol: :lol: :lol:
My OXP's
And Latest Mission Coyote's Run
Post Reply