Scripters cove

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

Moderators: winston, another_commander

User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4829
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Wildeblood wrote: Mon Aug 05, 2024 7:24 pm
I'm still having fun with screen backgrounds, and my next question is, can I switch off the rotating planet model on the F7 screen?
Not easily. I experimented with forcing the system to be a nova system (just temporarily), which would then allow you to manipulate the "system_data_nova" screen backgrounds id, but that was a bust. The nova settings for a system are readonly except for "system.sun.goNova" and "system.sun.cancelNova". But the "system_data_nova" background only applies if the sun has *gone* nova, at which point you can't "cancelNova" to change it back.

So my recommendation is that you'd need to replace the F7 screen with a custom mission screen, triggered whenever the player tries to visit the F7 screen.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2439
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

phkb wrote: Mon Aug 19, 2024 12:06 am
Wildeblood wrote: Mon Aug 05, 2024 7:24 pm
I'm still having fun with screen backgrounds, and my next question is, can I switch off the rotating planet model on the F7 screen?
Not easily. I experimented with forcing the system to be a nova system (just temporarily), which would then allow you to manipulate the "system_data_nova" screen backgrounds id, but that was a bust. The nova settings for a system are read-only...
Methinks, you do like to do things the hard way. If there's no "official" way to switch off the planet model, I would have tried experimenting with the planet's texture, attempting to make it transparent, or the planet's radius, trying to make it imperceptibly small, before I thought to mess about with the nova settings. Have you ever tried those approaches?
I thought the grey swan symbol was good, but when he said the new country's flag should be printed on "holographic" fabric, I began to doubt.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2439
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Can anyone offer any advice, how to proceed, here? This is my first attempt at a _checkForDamage function, which loops through player.ship.equipment until it finds something damaged, then returns true. Or, returns false if it gets all the way through.

Code: Select all

    this._checkForDamage = function () {
        "use strict";
        var self = player.ship;
        for (var i = 0; i < self.equipment.length; i++) {
            if (self.equipment[i].isVisible &&
                self.equipmentStatus(self.equipment[i]) === "EQUIPMENT_DAMAGED") {
                this._repairsNeeded = true;
                return true;
            }
        }
        this._repairsNeeded = false;
        return false;
    }
When it came time to make use of the function, I was somewhat disappointed at the result, and left myself this note:-

The flag, _repairsNeeded, is surprisingly frustrating.
It encourages me to check the F3 screen, where I learn
the repairs I need are not available on this low-tech
station. What's actually needed is a _repairsAvailable
flag.

So, that is the question, how does one find what equipment repairs are available at the current station, and compare them to what is needed?
User avatar
Cholmondely
Archivist
Archivist
Posts: 5329
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: Scripters cove

Post by Cholmondely »

Wildeblood wrote: Wed Sep 04, 2024 5:23 am
Can anyone offer any advice, how to proceed, here? This is my first attempt at a _checkForDamage function, which loops through player.ship.equipment until it finds something damaged, then returns true. Or, returns false if it gets all the way through.

Code: Select all

    this._checkForDamage = function () {
        "use strict";
        var self = player.ship;
        for (var i = 0; i < self.equipment.length; i++) {
            if (self.equipment[i].isVisible &&
                self.equipmentStatus(self.equipment[i]) === "EQUIPMENT_DAMAGED") {
                this._repairsNeeded = true;
                return true;
            }
        }
        this._repairsNeeded = false;
        return false;
    }
When it came time to make use of the function, I was somewhat disappointed at the result, and left myself this note:-

The flag, _repairsNeeded, is surprisingly frustrating.
It encourages me to check the F3 screen, where I learn
the repairs I need are not available on this low-tech
station. What's actually needed is a _repairsAvailable
flag.

So, that is the question, how does one find what equipment repairs are available at the current station, and compare them to what is needed?
Are there not OXPs which do this? And will have relevant code built in?

Here's a screen shot from Damage Report MFD:

Image

And the script should be on Hiran's database!
Comments wanted:
Missing OXPs? What do you think is missing?
Lore: The economics of ship building How many built for Aronar?
Lore: The Space Traders Flight Training Manual: Cowell & MgRath Do you agree with Redspear?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2439
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

I'll have a look. Ta.

LOL @ Nick's version history:

2.2.1
- Fixed missing ";" in Javascript file.
I thought the grey swan symbol was good, but when he said the new country's flag should be printed on "holographic" fabric, I began to doubt.
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2671
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

Re: Scripters cove

Post by Redspear »

Is there a recommended way to get the script from oxp A to run before the script from oxp B?

As author of both oxps (in this case) I should have considerable options but I do wish for the two scripts to remain seperate.

BTW 'startup' and 'startup complete' are not likely options as both scripts currently operate 'on the fly'.
User avatar
hiran
Theorethicist
Posts: 2384
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

Redspear wrote: Mon Oct 14, 2024 4:57 pm
Is there a recommended way to get the script from oxp A to run before the script from oxp B?
Interesting question indeed:
If multiple OXPs react on the same event (e.g. attackedByShip) are the OXPs' shipscripts invoked in parallel via multiple threads? Or invoked sequentially on the same thread?

If there is a sequence, is it guarantees to always be the same? And if it is the same, how can an OXP author influence it?
Sunshine - Moonlight - Good Times - Oolite
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2439
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

hiran wrote: Mon Oct 14, 2024 5:24 pm
If multiple OXPs react on the same event (e.g. attackedByShip) are the OXPs' shipscripts invoked in parallel via multiple threads? Or invoked sequentially on the same thread?

If there is a sequence, is it guarantees to always be the same? And if it is the same, how can an OXP author influence it?
Sequentially, the sequence being OS dependent, so not reliable, I believe.
I thought the grey swan symbol was good, but when he said the new country's flag should be printed on "holographic" fabric, I began to doubt.
User avatar
hiran
Theorethicist
Posts: 2384
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

Wildeblood wrote: Mon Oct 14, 2024 10:07 pm
hiran wrote: Mon Oct 14, 2024 5:24 pm
If multiple OXPs react on the same event (e.g. attackedByShip) are the OXPs' shipscripts invoked in parallel via multiple threads? Or invoked sequentially on the same thread?

If there is a sequence, is it guarantees to always be the same? And if it is the same, how can an OXP author influence it?
Sequentially, the sequence being OS dependent, so not reliable, I believe.
I do not know why Redspear asked but believe there is a good reason for it.
If we find the location where OXP references are kept in Oolite, maybe we can sort it and thus know the execution order. And we would know how to tweak it....
Sunshine - Moonlight - Good Times - Oolite
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2439
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

Redspear wrote: Mon Oct 14, 2024 4:57 pm
Is there a recommended way to get the script from oxp A to run before the script from oxp B?

As author of both oxps (in this case) I should have considerable options but I do wish for the two scripts to remain seperate.

BTW 'startup' and 'startup complete' are not likely options as both scripts currently operate 'on the fly'.
You just call the pertinent function in script A from script B, before script B does anything else relevant. This seems basic, so what are you not saying? You mention start-up, so are you talking about some kind of configuration process that only runs once, or about an event listener that will be repeatedly called?
I thought the grey swan symbol was good, but when he said the new country's flag should be printed on "holographic" fabric, I began to doubt.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2439
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: Scripters cove

Post by Wildeblood »

hiran wrote: Mon Oct 14, 2024 10:13 pm
If we find the location where OXP references are kept in Oolite, maybe we can sort it and thus know the execution order. And we would know how to tweak it....
A-C or phkb can confirm or correct this, but my understanding from days of yore is that scripts are run in the order they are first loaded into the cache, and that depends on the OS; on some it's alphabetically and on some it's by datestamp, etc.
I thought the grey swan symbol was good, but when he said the new country's flag should be printed on "holographic" fabric, I began to doubt.
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4829
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Scripters cove

Post by phkb »

Redspear wrote: Mon Oct 14, 2024 4:57 pm
Is there a recommended way to get the script from oxp A to run before the script from oxp B?
This is probably the easiest method I know (and by easiest I mean the fewest number of moving parts):

Code: Select all

"use strict";
this.name = "MyScriptA";

this.$function1 = function() {
    log(this.name, "This will always run first");
}

// this function would only be used if MyScriptB is present AND there are places in MyScriptA where $function1 is called.
// the assumption is, the same triggers apply to both MyScriptA and MyScriptB
// by creating an empty function, we can ensure the trigger only fires once, and be initated from MyScriptB
this.$function1_Inactive = function() {}

Code: Select all

"use strict";
this.name = "MyScriptB";

this._runFunction1 = false; // flag to indicate whether we need to run $function1

this.startUp = function() {
    // check if MyScriptA is present
    if (worldScripts.MyScriptA) {
        log(this.name, "Monkey-patching MyScriptA to ensure correct order of events");
        var ws = worldScripts.MyScriptA;
        // monkey-patch MyScriptA, moving $function1 to a new location and resetting the original function name
        ws.$function1_Hold = ws.$function1;
        ws.$function1 = ws.$function1_Inactive;
    
        // turn on flag so we know to call MyScriptA (saves having to go to the worldScripts object unless required)        
        this._runFunction1 = true;
    }
}

this.$function2 = function() {
    if (this._runFunction1) {
        // run the function in MyScriptA
        worldScripts.MyScriptA.$function1_Hold();
    }
    log(this.name, "This will always run second");
}
Hopefully that makes sense. Let me know if something requires additional explanation.

Yes, it's using the monkey-patch method, but given both scripts are in the author's control, the impact should be minimal.
Wildeblood wrote: Mon Oct 14, 2024 10:20 pm
scripts are run in the order they are first loaded into the cache, and that depends on the OS; on some it's alphabetically and on some it's by datestamp, etc.
Probably. Best rule of thumb is: If you need things run in a particular order, do it yourself.
User avatar
hiran
Theorethicist
Posts: 2384
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

Wildeblood wrote: Mon Oct 14, 2024 10:20 pm
hiran wrote: Mon Oct 14, 2024 10:13 pm
If we find the location where OXP references are kept in Oolite, maybe we can sort it and thus know the execution order. And we would know how to tweak it....
A-C or phkb can confirm or correct this, but my understanding from days of yore is that scripts are run in the order they are first loaded into the cache, and that depends on the OS; on some it's alphabetically and on some it's by datestamp, etc.
So there is a sequence, and seems to be stable (across running Oolite - even across all Oolites installed on the same OS).
Now imagine after loading all those scripts they get sorted once and thus the execution order is predictable for us. Not too big a change.
Sunshine - Moonlight - Good Times - Oolite
User avatar
Redspear
---- E L I T E ----
---- E L I T E ----
Posts: 2671
Joined: Thu Jun 20, 2013 10:22 pm
Location: On the moon Thought, orbiting the planet Ignorance.

Re: Scripters cove

Post by Redspear »

Wildeblood wrote: Mon Oct 14, 2024 10:15 pm
You mention start-up, so are you talking about some kind of configuration process that only runs once, or about an event listener that will be repeatedly called?
The latter.

phkb wrote: Mon Oct 14, 2024 11:12 pm
Hopefully that makes sense. Let me know if something requires additional explanation.
Thanks, I'll give that a try.

hiran wrote: Tue Oct 15, 2024 6:53 am
So there is a sequence, and seems to be stable (across running Oolite - even across all Oolites installed on the same OS).
Now imagine after loading all those scripts they get sorted once and thus the execution order is predictable for us. Not too big a change.
I thought it was alphabetical myself but that doesn't seem to always be the case.
User avatar
hiran
Theorethicist
Posts: 2384
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Scripters cove

Post by hiran »

hiran wrote: Tue Oct 15, 2024 6:53 am
Wildeblood wrote: Mon Oct 14, 2024 10:20 pm
A-C or phkb can confirm or correct this, but my understanding from days of yore is that scripts are run in the order they are first loaded into the cache, and that depends on the OS; on some it's alphabetically and on some it's by datestamp, etc.
So there is a sequence, and seems to be stable (across running Oolite - even across all Oolites installed on the same OS).
Now imagine after loading all those scripts they get sorted once and thus the execution order is predictable for us. Not too big a change.
Trying to find something I looked through the code, and somehow this caught my attention:
https://github.com/OoliteProject/oolite ... ity.h#L380

Is it that this NSDictionary collects all the world scripts? Could it be that a dictionary internally ends up to be a hashmap and therefore the sequence is not predictable? Could we change this to some container that preserves a sequence? As soon as it does, sorting can be applied...

I'd love to have a comment of someone with ObjectiveC experience or at least a working development environment to debug and verify the behaviour.

Edit: I can answer part of my questions: An NSDictionary does not guarantee any order. See this page: https://stackoverflow.com/questions/268 ... er-changes
Which means so far we have been lucky that the list looked sorted.
Sunshine - Moonlight - Good Times - Oolite
Post Reply