OK will download & have a look, thanks.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.
Newbie help with Oolite Js API
Moderators: winston, another_commander
Re: Newbie help with Oolite Js API
OXPs: Furball 1.8, Factions 1.12
Re: Newbie help with Oolite Js API
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.
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.
My OXPs via Boxspace or from my Wiki pages .
Thargoid TV
Dropbox Referral Link
Thargoid TV
Dropbox Referral Link
Re: Newbie help with Oolite Js API
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.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.
OXPs: Furball 1.8, Factions 1.12
Re: Newbie help with Oolite Js API
Edited requires.plist, now working, thanks.Ahruman wrote:Fixed, download it again.
OXPs: Furball 1.8, Factions 1.12
Re: Newbie help with Oolite Js API
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.
OXPs: Furball 1.8, Factions 1.12
- JensAyton
- Grand Admiral Emeritus
- Posts: 6657
- Joined: Sat Apr 02, 2005 2:43 pm
- Location: Sweden
- Contact:
Re: Newbie help with Oolite Js API
You can’t, but you don’t need to, because JavaScript functions “close over” variables in their declared scope. For example:Thargoid wrote:I'm not sure you can pass a parameter directly on a timer call to a function.
Code: Select all
var x = 5;
this.t = new Timer(this, function() { log(x); }, 0); // Will log 5
Code: Select all
function timerFunction(n)
{
log(n);
}
var x = 5;
this.t = new Timer(this, function() { timerFunction(x); }, 0);
E-mail: [email protected]
Re: Newbie help with Oolite Js API
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.
OXPs: Furball 1.8, Factions 1.12
Re: Newbie help with Oolite Js API
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!
OXPs: Furball 1.8, Factions 1.12
Re: Newbie help with Oolite Js API
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"
OK so I'm a PC user - "you know whats scary? Out of billions of sperm I was the fastest"
- Okti
- ---- 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
TGHC wrote:round of applause to everyone, more jelly babies.