Page 1 of 1

Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 11:19 am
by UK_Eliter
I'm having trouble finding out how to make use of ship event handlers of the kind one would use in worldscripts - this.shipDockedWithStation, etc. - from within script that is attached to a piece of equipment. I need to be able to do that (or something like it) because I need to do stuff with timers (esp. abort them) on docking or witchspace jump, etc.

I've tried just putting the handlers within the equipment script, but they don't seem to fire. And if I were to have an equipment script and a world script, I don't know how I'd get timers set by the equipment script to be alterable by the world script.

Advice? Sorry if the info is out there already and I've missed it.

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 11:29 am
by Commander McLane
I have no experience yet with equipment scripts, and the Wiki seems currently to be down, so I can't check, but from what I've understood so far, equipment scripts are only for checking conditions when the F3-screen is created, and basically determine whether the equipment in question will be displayed as available or not.

Thus, doing or checking anything after the equipment is installed still has to be done in your world script.

EDIT: see the Oolite 1.77 announcement and the 1.77 introduction for OXPers.

So, in short, there are no "equipment scripts", but only "conditions for equipment availability scripts".

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 11:36 am
by cim
Neither equipment operation scripts nor equipment condition scripts use world script event handlers. If you need the equipment to pay attention to them, the easiest way is to have a worldscript manage the equipment, timers, etc., and then have a very short equipment script that just relays commands:

Code: Select all

this.activated = function() 
{
  worldScripts["My Equipment Script"]._activateEquipment();  
}
Have a look at my Camera OXP for an example.

EDIT: corrected code example as noted below

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 12:07 pm
by Svengali
cim wrote:
Neither equipment operation scripts nor equipment condition scripts use world script event handlers. If you need the equipment to pay attention to them, the easiest way is to have a worldscript manage the equipment, timers, etc., and then have a very short equipment script that just relays commands:
And equipment scripts are not accessible for other scripts. It's a one-way ticket .-)
Commander McLane wrote:
So, in short, there are no "equipment scripts", but only "conditions for equipment availability scripts".
No.

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 1:13 pm
by UK_Eliter
Thanks for the help, everyone. Great!

But in

Code: Select all

this.activate = function()
{
  worldScripts["My Equipment Script"]._activateEquipment(); 
}
It should actually be this.activated, right?

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 2:55 pm
by cim
UK_Eliter wrote:
It should actually be this.activated, right?
Yes, sorry. Typing from memory because I couldn't get at the wiki.

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 2:58 pm
by Commander McLane
UK_Eliter wrote:
But in

Code: Select all

this.activate = function()
{
  worldScripts["My Equipment Script"]._activateEquipment(); 
}
It should actually be this.activated, right?
Yes.
Svengali wrote:
Commander McLane wrote:
So, in short, there are no "equipment scripts", but only "conditions for equipment availability scripts".
No.
You're right, of course. I forgot about the scripts for primeable equipment, and only thought of the new equipment condition scripts. :oops:

Re: Equipment scripts (and how they relate to worldscripts)

Posted: Wed Mar 27, 2013 4:42 pm
by Eric Walch
And the future 1.77 equipment method

Code: Select all

this.mode = function ()
{
  // your code
}
for action on the 'b' key was missing in the wiki.