Scripters cove
Moderators: winston, another_commander
- phkb
- Commodore
- Posts: 2438
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Re: Scripters cove
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.
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.
Re: Scripters cove
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. 

Trying to survive behind the controls of a Caduceus Psi XT in Alpha test 

Re: Scripters cove
I'm experiencing a problem (I think it's a problem) with the
Here is the code that doesn't work:
Oolite starts barfing up reference errors:
But when I take the function body from
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
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]();}
}
}
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.
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?- phkb
- Commodore
- Posts: 2438
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Re: Scripters cove
I'm not JS expert, but shouldn't this line:
be this?:
I just tested this form and that seems to work OK.
Code: Select all
this._CD_addEquipment(equipment)
Code: Select all
this._CD_addEquipment = function(equipment)
Re: Scripters cove
Bingo! Dead on the money!phkb wrote: ↑Fri Aug 16, 2019 4:16 amI'm not JS expert, but shouldn't this line:be this?:Code: Select all
this._CD_addEquipment(equipment)
I just tested this form and that seems to work OK.Code: Select all
this._CD_addEquipment = function(equipment)
It's amazing how you look right at something and not see it...

Re: Scripters cove
A simple task, or so I thought, however the result is not exactly as expected. I created a new commodity:
and added a simple market script to it:
While I receive some errors in the log:
16:57:26.666 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (Artifacts 0.5.0): TypeError: station is null
16:57:26.666 [script.commodityScript.error]: Could not update general commodity definition for [commodity-name holy_artifacts] - unable to call updateLocalCommodityDefinition
I could say after some testing that it seems to work, exception is the main station where all my updates are ignored. Anybody has an idea what I missed or did simply wrong ?
Code: Select all
"holy_artifacts" =
{
"name" = "[commodity-name holy_artifacts]";
"classes" = ("oolite-consumer", "oolite-luxury");
"comment" = "religious Artifacts, good luck charms and protection chants";
"quantity_unit" = 1; // kg
"peak_export" = 0; // Mainly Industrial
"peak_import" = 7; // Poor Agricultural
"price_average" = 3500; // decicredits
"price_economic" = 0.48;
"price_random" = 0.03;
"quantity_average" = 13.5;
"quantity_economic" = 0.52;
"quantity_random" = 1.15;
"legality_export" = 0.0;
"legality_import" = 0.0;
"trumble_opinion" = 0.0;
"market_script" = "SGNS-dictator_clergy_market.js";
"sort_order" = 1695;
};
Code: Select all
this.updateGeneralCommodityDefinition = function(goodDefinition, station, systemID)
{
if (station && station.allegiance != "pirate" && station.allegiance != "chaotic" && system.info.government === 4)
{
goodDefinition.capacity = "0";
goodDefinition.legality_export = "2";
goodDefinition.legality_import = "2";
}
return goodDefinition;
}
16:57:26.666 [script.javaScript.exception.unexpectedType]: ***** JavaScript exception (Artifacts 0.5.0): TypeError: station is null
16:57:26.666 [script.commodityScript.error]: Could not update general commodity definition for [commodity-name holy_artifacts] - unable to call updateLocalCommodityDefinition
I could say after some testing that it seems to work, exception is the main station where all my updates are ignored. Anybody has an idea what I missed or did simply wrong ?
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test 

- phkb
- Commodore
- Posts: 2438
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: [p]laying [h]ard and [k]icking [b]utt somewhere in G7...
Re: Scripters cove
Just a quick check: you need to put your commodity definition inside another set of braces, like this:
Code: Select all
{
"holy_artifacts" =
{
...
};
}
Re: Scripters cove
Thanks phkb, since I still find typos and copy & past errors in code I checked several times before it was a good hint, however, this time unfortunatly not the solution. Here the complete code:
Code: Select all
{
"holy_artifacts" =
{
"name" = "[commodity-name holy_artifacts]";
"classes" = ("oolite-consumer", "oolite-luxury");
"comment" = "religious Artifacts, good luck charms and protection chants";
"quantity_unit" = 1; // kg
"peak_export" = 0; // Mainly Industrial
"peak_import" = 7; // Poor Agricultural
"price_average" = 3500; // decicredits
"price_economic" = 0.48;
"price_random" = 0.03;
"quantity_average" = 13.5;
"quantity_economic" = 0.52;
"quantity_random" = 1.15;
"legality_export" = 0.0;
"legality_import" = 0.0;
"trumble_opinion" = 0.0;
"market_script" = "SGNS-dictator_clergy_market.js";
"sort_order" = 1695;
};
}
Code: Select all
this.name = "Artifacts";
this.author = "Montana05";
this.description = "Artifact restrictions";
this.version = "0.5.0";
this.copyright = "Creative Commons: attribution, non-commercial, share-alike.";
this.licence = "CC BY-NC-SA";
"use strict";
// Feel free to use in any way you like as long as its non-commercial
// Communists just hate them
this.updateGeneralCommodityDefinition = function(goodDefinition, station, systemID)
{
if (station && station.allegiance != "pirate" && station.allegiance != "chaotic" && system.info.government === 4)
{
goodDefinition.capacity = "0";
goodDefinition.legality_export = "2";
goodDefinition.legality_import = "2";
}
return goodDefinition;
}
Edit:
Btw I think I found a solution to put the loaders of the imperial freighters to work, I am using it now for shuttles and didn't run in any errors for a while now. I intend to fix a logical error (prison ships and astrofactories never meet) by introducing an inter-dictator-traffic, probably including clerics as well.
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test 
