Equipment scripts (and how they relate to worldscripts)

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

Moderators: winston, another_commander

Post Reply
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1248
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

Equipment scripts (and how they relate to worldscripts)

Post 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.
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: Equipment scripts (and how they relate to worldscripts)

Post 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".
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

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

Post 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
Last edited by cim on Wed Mar 27, 2013 3:14 pm, edited 1 time in total.
User avatar
Svengali
Commander
Commander
Posts: 2370
Joined: Sat Oct 20, 2007 2:52 pm

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

Post 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.
UK_Eliter
---- E L I T E ----
---- E L I T E ----
Posts: 1248
Joined: Sat Sep 12, 2009 11:58 pm
Location: Essex (mainly industrial and occasionally anarchic)

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

Post 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?
User avatar
cim
Quite Grand Sub-Admiral
Quite Grand Sub-Admiral
Posts: 4072
Joined: Fri Nov 11, 2011 6:19 pm

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

Post 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.
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: Equipment scripts (and how they relate to worldscripts)

Post 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:
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: Equipment scripts (and how they relate to worldscripts)

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