Scripters cove
Moderators: winston, another_commander
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
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.
- montana05
- ---- E L I T E ----
- Posts: 1166
- Joined: Mon May 30, 2016 3:54 am
- Location: lurking in The Devils Triangle (G1)
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.
Scars remind us where we've been. They don't have to dictate where we're going.
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
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
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...
- montana05
- ---- E L I T E ----
- Posts: 1166
- Joined: Mon May 30, 2016 3:54 am
- Location: lurking in The Devils Triangle (G1)
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 ?
Scars remind us where we've been. They don't have to dictate where we're going.
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
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" =
{
...
};
}
- montana05
- ---- E L I T E ----
- Posts: 1166
- Joined: Mon May 30, 2016 3:54 am
- Location: lurking in The Devils Triangle (G1)
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.
Scars remind us where we've been. They don't have to dictate where we're going.
- montana05
- ---- E L I T E ----
- Posts: 1166
- Joined: Mon May 30, 2016 3:54 am
- Location: lurking in The Devils Triangle (G1)
Re: Scripters cove
Happy New Year, no preassure ment but any ideas yet what could be the reason for the problem ?
Scars remind us where we've been. They don't have to dictate where we're going.
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Scripters cove
I’m going on a family holiday and won’t have access to do debugging until the end of the month. I will look at this more closely then.
Re: Scripters cove
Hi,
I was wondering why the timeAccelerationFactor (http://wiki.alioth.net/index.php/Oolite ... tionFactor) is only writeable in the dev-version of Oolite. Are there some side effects other than speeding up the game that one should know about before using it in an OXP?
I was wondering why the timeAccelerationFactor (http://wiki.alioth.net/index.php/Oolite ... tionFactor) is only writeable in the dev-version of Oolite. Are there some side effects other than speeding up the game that one should know about before using it in an OXP?
- Cody
- Sharp Shooter Spam Assassin
- Posts: 16081
- Joined: Sat Jul 04, 2009 9:31 pm
- Location: The Lizard's Claw
- Contact:
Re: Scripters cove
The TAF is seen as a dev tool, and not for normal gameplay (it was disabled in Oolite 1.77), but I'm not aware of any side effects.
I would advise stilts for the quagmires, and camels for the snowy hills
And any survivors, their debts I will certainly pay. There's always a way!
And any survivors, their debts I will certainly pay. There's always a way!
-
- Quite Grand Sub-Admiral
- Posts: 6682
- Joined: Wed Feb 28, 2007 7:54 am
Re: Scripters cove
I think the main issue with enabling TAF unconditionally was that we could not guarantee that AI routines, especially ones like attacking, docking and sun-skimming, would continue to function exactly as expected at high time accelerations. Having said that, I think that most work fine up to a TAF of x4. Time deceleration could also be used for creating bullet time effects, but that would probably fit more with story-driven OXPs.
- phkb
- Impressively Grand Sub-Admiral
- Posts: 4830
- Joined: Tue Jan 21, 2014 10:37 pm
- Location: Writing more OXPs, because the world needs more OXPs.
Re: Scripters cove
OK, back in the saddle! Sorry the the break in transmission!
Right, market scripts for new commodities. If I understand the logic correctly, you're trying to make the main station (or any neutral or GalCop station) deal with artefacts as illegal goods, and also making sure these stations don't have any units available for purchase. The trick I found was that, in the
updateGeneralCommodityDefinition
function, it's never called for the main station. It's called for every other station, but, from the games point of view, the system definition for a commodity is the same thing as the main station's definition. So, in your case, because your exception is the main station, you need to do something slightly different to achieve what you want.Here's something I prepared earlier: Artefacts.zip (Apologies for changing "artifacts" to "artefacts". Australian spelling). In this zip is an OXP which has the Holy Artefacts implemented in the way I think you want them: illegal to import or export in communist systems, except at pirate or chaotic stations, and with 0 units at those stations where they're illegal. What I did was add a world script that calls "systemWillPopulate". The main station should be accessible at this point during, so I'm just setting the quantity to zero at this point. All other stations will be handled by the market script.
I've done some limited testing on this, and it seems to work OK, but let me know if you run into problems.
- montana05
- ---- E L I T E ----
- Posts: 1166
- Joined: Mon May 30, 2016 3:54 am
- Location: lurking in The Devils Triangle (G1)
Re: Scripters cove
Welcome back phkb, I hope you had a great time with your family.phkb wrote: ↑Wed Feb 19, 2020 1:08 pmHere's something I prepared earlier: Artefacts.zip (Apologies for changing "artifacts" to "artefacts". Australian spelling). In this zip is an OXP which has the Holy Artefacts implemented in the way I think you want them: illegal to import or export in communist systems, except at pirate or chaotic stations, and with 0 units at those stations where they're illegal. What I did was add a world script that calls "systemWillPopulate". The main station should be accessible at this point during, so I'm just setting the quantity to zero at this point. All other stations will be handled by the market script.
I've done some limited testing on this, and it seems to work OK, but let me know if you run into problems.
Thank you very much for your help, I got frustrated already because actually it was a simple idea. However, after some hours of testing today, I didn't find any problems, your code got exactly the result I had in mind. Some tuning will be required (pirate coves for example needed to be addressed by main-role) but finally the basic is working. Thank you again.
Scars remind us where we've been. They don't have to dictate where we're going.