Scripters cove

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

Moderators: winston, another_commander

User avatar
phkb
Commodore
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

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: 282
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: 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

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:

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

Re: Scripters cove

Post by montana05 » Tue Dec 03, 2019 10:08 am

A simple task, or so I thought, however the result is not exactly as expected. I created a new commodity:

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;
};
and added a simple market script to it:

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;
}
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 ?
Trying to survive behind the controls of a Caduceus Psi XT in Alpha test :lol:

User avatar
phkb
Commodore
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

Post by phkb » Tue Dec 03, 2019 9:18 pm

montana05 wrote:
Tue Dec 03, 2019 10:08 am
I created a new commodity
Just a quick check: you need to put your commodity definition inside another set of braces, like this:

Code: Select all

{
    "holy_artifacts" = 
    {
    	...
    };
 }
You might be doing this already, and just copied the definition code, but it's worth checking.

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

Re: Scripters cove

Post by montana05 » Wed Dec 04, 2019 12:39 am

phkb wrote:
Tue Dec 03, 2019 9:18 pm
You might be doing this already, and just copied the definition code, but it's worth checking.
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;
}
Basic idea is to ban import and export in communist systems and make sure that no stock is available at stations. Excluded are only "sleezy" stations.

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 :lol:

Post Reply