Scripters cove

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

Moderators: winston, another_commander

User avatar
phkb
Commodore
Commodore
Posts: 2403
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Wed Aug 14, 2019 4:58 am

Hmm. The wiki says the subEntities property is read only, which would seem to limit that method. But it wouldn't be the first time the wiki is out of date. I'll have a go and see what I can break!

In any case, I have a fallback position where I define both of those sub-entities in the shipdata, and then remove the appropriate one based on active/inactive status.

User avatar
montana05
---- E L I T E ----
---- E L I T E ----
Posts: 272
Joined: Mon May 30, 2016 3:54 am

Re: Scripters cove

Post by montana05 » Wed Aug 14, 2019 5:56 am

That should work, overlaying 2 models (active and inactive) and remove or restore the active one when needed. I tired another approach by setting the max_energy to 0, needless to say the turret keep on firing. :lol:
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:

User avatar
Phasted
Competent
Competent
Posts: 50
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted » Fri Aug 16, 2019 2:54 am

I'm experiencing a problem (I think it's a problem) with the equipmentAdded event handler. The argument ("equipmentKey") isn't being passed consistently.

Here is the code that doesn't work:

Code: Select all

this.equipmentAdded = function(equipment) {this._CD_addEquipment(equipment);}

this._CD_addEquipment(equipment)
{
  var cOS = "_CD_checkOnStuff", iR = "isRunning", s = "start", t = "timer";
  if(equipment === "EQ_TRUMBLE")
  {
    if(!this[cOS][t]) {this[cOS][t] = new Timer(this, this[cOS], 60, 90);}
    else if(!this[cOS][t][iR]) {this[cOS][t][s]();}
  }
}
Oolite starts barfing up reference errors:

Code: Select all

21:13:19.422 [script.javaScript.exception.notDefined]: ***** JavaScript exception (CD_change-difficulty): ReferenceError: equipment is not defined
21:13:19.422 [script.javaScript.load.failed]: ***** Error loading JavaScript script ../AddOns/ChangeDifficulty.oxp/Scripts/CD_change-difficulty.js -- could not run script
21:13:19.422 [script.load.notFound]: ***** ERROR: Could not find script file CD_change-difficulty.js.
But when I take the function body from this._CD_addEquipment and attach it directly to the event handler, it works fine...

I'd rather not do it that way (I think that event handlers should be nice, neat one-liners...), but it's the only way that seems to work...

Is this.equipmentAdded broken somehow? Or am I just missing something?

User avatar
phkb
Commodore
Commodore
Posts: 2403
Joined: Tue Jan 21, 2014 10:37 pm
Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...

Re: Scripters cove

Post by phkb » Fri Aug 16, 2019 4:16 am

I'm not JS expert, but shouldn't this line:

Code: Select all

this._CD_addEquipment(equipment)
be this?:

Code: Select all

this._CD_addEquipment = function(equipment)
I just tested this form and that seems to work OK.

User avatar
Phasted
Competent
Competent
Posts: 50
Joined: Wed Jun 09, 2010 3:56 pm

Re: Scripters cove

Post by Phasted » Fri Aug 16, 2019 1:25 pm

phkb wrote:
Fri Aug 16, 2019 4:16 am
I'm not JS expert, but shouldn't this line:

Code: Select all

this._CD_addEquipment(equipment)
be this?:

Code: Select all

this._CD_addEquipment = function(equipment)
I just tested this form and that seems to work OK.
Bingo! Dead on the money!

It's amazing how you look right at something and not see it... :oops:

Post Reply