Page 1 of 1
Oolite Debug Console to control OXP behaviour?
Posted: Mon Jun 10, 2024 7:26 pm
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?
Re: Oolite Debug Console to control OXP behaviour?
Posted: Mon Jun 10, 2024 11:49 pm
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.
Re: Oolite Debug Console to control OXP behaviour?
Posted: Tue Jun 11, 2024 1:46 am
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.
Re: Oolite Debug Console to control OXP behaviour?
Posted: Tue Jun 11, 2024 4:50 am
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.
Re: Oolite Debug Console to control OXP behaviour?
Posted: Tue Jun 11, 2024 9:13 am
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?)
Re: Oolite Debug Console to control OXP behaviour?
Posted: Tue Jun 11, 2024 6:57 pm
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:
Re: Oolite Debug Console to control OXP behaviour?
Posted: Wed Jun 12, 2024 9:55 am
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.)
What is preventing anyone creating an Autopilot OXP?
Posted: Wed Jun 12, 2024 10:01 am
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:
Ship speed is read only.
Re: What is preventing anyone creating an Autopilot OXP?
Posted: Wed Jun 12, 2024 2:07 pm
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.
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...
Re: What is preventing anyone creating an Autopilot OXP?
Posted: Wed Jun 12, 2024 3:45 pm
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.
Re: What is preventing anyone creating an Autopilot OXP?
Posted: Wed Jun 12, 2024 4:09 pm
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.
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.
Re: What is preventing anyone creating an Autopilot OXP?
Posted: Wed Jun 12, 2024 6:54 pm
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.
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.