Join us at the Oolite Anniversary Party -- London, 7th July 2024, 1pm
More details in this thread.

Oolite Debug Console to control OXP behaviour?

General discussion for players of Oolite.

Moderators: winston, another_commander

Post Reply
User avatar
hiran
Theorethicist
Posts: 2195
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Oolite Debug Console to control OXP behaviour?

Post by hiran »

I am sure you can use the Oolite Debug Console and enter commands that control Oolite.
But is it possible to change the behaviour of a specific OXP? How would I do that?
Sunshine - Moonlight - Good Times - Oolite
User avatar
phkb
Impressively Grand Sub-Admiral
Impressively Grand Sub-Admiral
Posts: 4746
Joined: Tue Jan 21, 2014 10:37 pm
Location: Writing more OXPs, because the world needs more OXPs.

Re: Oolite Debug Console to control OXP behaviour?

Post by phkb »

That would depend on the mod. Each mod would have individual functions that could be called to do various things, but there wouldn’t be any consistency between then. For primable equipment there could be a possibility of calling the activate or mode functions as long as the functions could be accessed via a worldscript. Unfortunately that isn’t guaranteed.

I think if you’re aiming to set up a secondary screen to replicate things that happen on the main screen via mods, it might need to be done on a case by case basis. Because even if you could perform the activate and mode functions, those mods will be designed to send their output to main screen in whatever form that might be. Each mod might need to be tweaked to have the options of just returning their output as the result of a function call.
User avatar
MrFlibble
Deadly
Deadly
Posts: 217
Joined: Sun Feb 18, 2024 12:13 pm

Re: Oolite Debug Console to control OXP behaviour?

Post by MrFlibble »

We may have been spoiled by "http simple" in python, or even ncat/socat on linux. </lowlevel>

Surely there's a way to make MFD's spit out to http (frames!) while making the active ones obvious with maybe an asterisk or some-such!?

<newbie>Ill get back in my box.
User avatar
hiran
Theorethicist
Posts: 2195
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Oolite Debug Console to control OXP behaviour?

Post by hiran »

Ok I admit I am not after generic OXP control.
If I can modify a variable or call one OXP's function that would be good already. This function is yet to be created.

So let's assume I want to turn some functionality on and off. The OXP would have a variable to remember the state.

How can someone via the debug console modify that state? Would it be good to have two functions (on and off) or better one function (setState with a param)?

I am uncomfortable with javascript code so a cut&paste example would be wecome.
Sunshine - Moonlight - Good Times - Oolite
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2321
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Oolite Debug Console to control OXP behaviour?

Post by Wildeblood »

The debug console interacts with Oolite using a "world script". All Oolite world scripts are merged into one big script at load time/share a common namespace/terminology of your choice to convey this concept. So one world script can simply reach into another and twiddle things at any time using the syntax:

worldScripts["Your Script Name"].$yourVariable = param;
or
worldScripts["Your Script Name"]._yourFunction(param);

The syntax doesn't change when entered directly into the console.

A simple example: Turbotrader is a script whose sole purpose is to twiddle some variables in another script, called Autotrade, at start up. Here it is:

Code: Select all

this.name    = "AI Turbotrader";
this.version = "2.12.4";

/*   OVER-WRITE AUTOTRADE TIMER SETTINGS   */

    this.startUp = function () {
        "use strict";
        let ws = worldScripts["AI Autotrade"];
        if (ws) {
            ws.$firstWarning   = 6;  // Seconds until $startMessage is displayed.
            ws.$firstAdvice    = 9;  // Seconds until first recommendation is displayed.
            ws.$firstTrade     = 11; // Seconds until first trade is executed.
            ws.$tradePeriod    = 4;  // Seconds between consecutive trades.
        }
        delete this.startUp;
    }

/*   THE END   */
(Will edit with a better example in a few minutes.)

Okay, Explorers' Club contains this function, which it never actually uses itself. It's only there for other world scripts (such as the debug console) to interrogate.

Code: Select all

    this._playerVisited = function (galaxy, sysID) {
        "use strict";
        if (this.startUp) {
            this.startUp();
        }
        if (typeof(sysID) === "undefined") {
            return "bad parameters";
        }
        if (galaxy < 0 ||
            galaxy > 7) {
            return "bad galaxy";
        }
        if (sysID < 0 ||
            sysID > 255) {
            return "bad system";
        }
        if (this.$xc_record[galaxy].indexOf(sysID) === -1) {
            return false;
        } else {
            return true;
        }
    }
There's a note inside the OXP, for anyone snooping around to find, which explains its use:
FUNCTIONS FOR OTHER OXPs

Other scripts can call this function:-

worldScripts["Explorers Club"]._playerVisited(galaxy, sysID)

Returns true or false, depending on whether or not the player has visited the given system since installing Explorers' Club. E.g.

worldScripts["Explorers Club"]._playerVisited(0, 7)

returns false if there is no record of the player visiting Lave.
So, directly entered into the console:-
worldScripts["Explorers Club"]._playerVisited(0, 7)

From within another world script:-
let lave = worldScripts["Explorers Club"]._playerVisited(0, 7)
creates a local variable called "lave", which is either true or false.

For the simple scripts I've created, I've not needed to use a function to change variables within them, just twiddled the variable directly. I've only used function calls to get information out.

(Am I barking up the right tree here, Hiran? I've not had much sleep this week. Is this a meaningful reply to your query?)
"Would somebody stop that bloody music!"
User avatar
hiran
Theorethicist
Posts: 2195
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: Oolite Debug Console to control OXP behaviour?

Post by hiran »

Thank you Wildeblood.
This gave me an idea, but I seem to have problems implementing it. Here is my world script, which actually looks simple:
https://github.com/OoliteProject/Oolite ... /script.js

The script serves two purposes:
- When the player saves the game, ensure the currently active OXPs get recorded as mission variable.
- Push flight data out via the debug interface so it can be forwarded to MQTT

The second part can take processing time that is not necessary if debugging is not used anyway. That's why I want to control that feature via this variable:
https://github.com/OoliteProject/Oolite ... ipt.js#L12

Now I see three problems:
- How do I modify that variable? This command does not show the desired effect:

Code: Select all

worldScripts["oolite-starter-oxp"].$pushdata = true
- How does the script have to look like so I do not get such output in the Oolite log?

Code: Select all

20:32:42.039 [script.javaScript.exception.cyclicValue]: ***** JavaScript exception (oolite-starter-oxp 0.1): TypeError: cyclic object value
20:32:42.039 [script.javaScript.exception.cyclicValue]:       AddOns/org.oolite.hiran.OoliteStarter.oxp/Config/script.js, line 74.
- What debug console command would I need to set the ship speed to a numeric value (e.g. 90)? The below does not work for me:

Code: Select all

player.ship.speed = 90
Sunshine - Moonlight - Good Times - Oolite
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2321
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: Oolite Debug Console to control OXP behaviour?

Post by Wildeblood »

hiran wrote: Tue Jun 11, 2024 6:57 pm
- How do I modify that variable? This command does not show the desired effect:

Code: Select all

worldScripts["oolite-starter-oxp"].$pushdata = true

Code: Select all

    this.$fcb = addFrameCallback(function (delta)
    {
        if (pushdata!=true)
            return;

Code: Select all

this.alertConditionChanged = function(newCondition, oldCondition)
{
    if (this.pushdata!=true)
            return;

Code: Select all

this.commsMessageReceived = function(message, sender)
{
    if (this.pushdata!=true)
        return;
What happened, hiran? How did you solve it? Was it something simple, like adding a magic "this" to line 25?

Code: Select all

    this.$fcb = addFrameCallback(function (delta)
    {
        if (this.pushdata!=true)
            return;
(I would not start a frame callback at startUp, but wait for startUpComplete.)
"Would somebody stop that bloody music!"
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2321
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

What is preventing anyone creating an Autopilot OXP?

Post by Wildeblood »

hiran wrote: Tue Jun 11, 2024 6:57 pm
What debug console command would I need to set the ship speed to a numeric value (e.g. 90)? The below does not work for me:

Code: Select all

player.ship.speed = 90
Ship speed is read only. :mrgreen:
User avatar
hiran
Theorethicist
Posts: 2195
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: What is preventing anyone creating an Autopilot OXP?

Post by hiran »

Wildeblood wrote: Wed Jun 12, 2024 9:55 am
hiran wrote: Tue Jun 11, 2024 6:57 pm
- How do I modify that variable? This command does not show the desired effect:

Code: Select all

worldScripts["oolite-starter-oxp"].$pushdata = true
[...]
What happened, hiran? How did you solve it? Was it something simple, like adding a magic "this" to line 25?
No, I did not add a 'this', I had to remove one that existed before. ;-)
Plus the locations you listed are those that consume the variable - they do not modify it.
Wildeblood wrote: Wed Jun 12, 2024 9:55 am

Code: Select all

    this.$fcb = addFrameCallback(function (delta)
    {
        if (this.pushdata!=true)
            return;
(I would not start a frame callback at startUp, but wait for startUpComplete.)
Noted. I will change it and see what happens. (where is the :tumbs_up: smilie?)
Wildeblood wrote: Wed Jun 12, 2024 10:01 am
hiran wrote: Tue Jun 11, 2024 6:57 pm
What debug console command would I need to set the ship speed to a numeric value (e.g. 90)?
Ship speed is read only. :mrgreen:
So what is the way to control the ship speed from the debug console? I also had no luck with desiredSpeed. Should I use setSpeedFactor()?
If it exists, it is not documented...
Sunshine - Moonlight - Good Times - Oolite
User avatar
hiran
Theorethicist
Posts: 2195
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: What is preventing anyone creating an Autopilot OXP?

Post by hiran »

hiran wrote: Wed Jun 12, 2024 2:07 pm
Wildeblood wrote: Wed Jun 12, 2024 9:55 am
(I would not start a frame callback at startUp, but wait for startUpComplete.)
Noted. I will change it and see what happens. (where is the :tumbs_up: smilie?)
So that one worked. The new code is now online.
Sunshine - Moonlight - Good Times - Oolite
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2321
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia

Re: What is preventing anyone creating an Autopilot OXP?

Post by Wildeblood »

hiran wrote: Wed Jun 12, 2024 2:07 pm
Wildeblood wrote: Wed Jun 12, 2024 10:01 am
hiran wrote: Tue Jun 11, 2024 6:57 pm
What debug console command would I need to set the ship speed to a numeric value (e.g. 90)?
Ship speed is read only. :mrgreen:
So what is the way to control the ship speed from the debug console? I also had no luck with desiredSpeed. Should I use setSpeedFactor()?
If it exists, it is not documented...
It does not exist. If ship speed were controllable by javascript, we would have had autopilot OXPs long ago. You could experiment with maxSpeed, though, that one is read/write.
User avatar
hiran
Theorethicist
Posts: 2195
Joined: Fri Mar 26, 2021 1:39 pm
Location: a parallel world I created for myself. Some call it a singularity...

Re: What is preventing anyone creating an Autopilot OXP?

Post by hiran »

Wildeblood wrote: Wed Jun 12, 2024 4:09 pm
hiran wrote: Wed Jun 12, 2024 2:07 pm
Wildeblood wrote: Wed Jun 12, 2024 10:01 am


Ship speed is read only. :mrgreen:
So what is the way to control the ship speed from the debug console? I also had no luck with desiredSpeed. Should I use setSpeedFactor()?
If it exists, it is not documented...
It does not exist. If ship speed were controllable by javascript, we would have had autopilot OXPs long ago. You could experiment with maxSpeed, though, that one is read/write.
Oh. So the JavaScript console is a lot more limited than I had anticipated.

Someone asked whether we would have additional panels just for displaying Oolite status or whether it would be possible to also control the ship.
I created a small UI that displays the current ship speed, but that would on the other hand also allow a user to set the speed. This one meanwhile gets communicated back to Oolite but it does not react on the new ship speed.

Thus we'd have to find out what other actions could or could not be done.
Sunshine - Moonlight - Good Times - Oolite
Post Reply