p.s.torusEngaged & p.s.injectorsEngaged Booleans

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

Moderators: winston, another_commander

User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

Because "Muh framerate" and other reasons, my interest in space combat is zero. I decided a teleporting cheat script was in order. Conceptually, it's the simplest thing in the world:

player.ship.position = this._myPlaceIReallyWouldPreferToBe.position

Simple. In concept. A simple one afternoon task, no need for any bells and whistles. No need for any emails to the player saying, "Congratulations, you are now the proud owner of a Cheatonics Mk 2 teleporter."

No need. None. One afternoon. Have it fished by tea-time, see it work.

This will be day three; it still doesn't work. The main reason remaining for its unworkingness seems to be that the p.s.torusEngaged & p.s.injectorsEngaged Booleans appear to behave the way Someone Else thought they should behave, but I'm unsure. It could be something else entirely. But, let us ask the question „Wo ist die Dokumentation?“

https://wiki.alioth.net/index.php/Oolit ... orsEngaged
injectorsEngaged
This property was added in Oolite test release 1.81.

injectorsEngaged : Boolean(read-only)
Is the player ship currently using fuel injection.
https://wiki.alioth.net/index.php/Oolit ... rusEngaged
torusEngaged
This property was added in Oolite test release 1.81.

torusEngaged : Boolean(read-only)
Is the player ship currently using torus drive.
Imagine this scenario, gentle reader:-

Code: Select all

if (validDestination) {
    if (p.s.injectorsEngaged) {
        Wee, teleport!
        validDestination = false;
    }
}
It works! Send that email!
Change compass target (at which point we'll again have a valid destination).
Wee, teleport again!
What the heck? 
My finger no longer depresseth the injectors key-button-thingy, why are we teleporting again?
MY ACTUAL QUESTION: how long after my fingertip ceaseth to depress the relevant key does it take for the p.s.torusEngaged or p.s.injectorsEngaged Booleans to revert to false? If the answer is "milliseconds", I'm obviously barking up the wrong tree, because I'm checking with a 0.5 second timer. Serious question. And, the sort of detail the "documentation" should have.

(Because apparently „Wo ist der Dokumentation?“ is not a legitimate question in any man's language.)
User avatar
phkb
Impressively Grand Sub-Admiral
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: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by phkb »

Wildeblood wrote: Fri Feb 16, 2024 11:43 pm
how long after my fingertip ceaseth to depress the relevant key does it take for the p.s.torusEngaged or p.s.injectorsEngaged Booleans to revert to false?
In my testing, instantly.

Put this code into a worldScript somewhere:

Code: Select all

this.shipWillLaunchFromStation = function() {
    this._injectors = false;
    this._torus = false;
    this._fcb = addFrameCallback(function(delta) {
        var makeSound = false;
        if (player.ship.injectorsEngaged != worldScripts["my_worldscript_name"]._injectors) {
            worldScripts["my_worldscript_name"]._injectors = player.ship.injectorsEngaged;
            makeSound = true;
        }
        if (player.ship.torusEngaged != worldScripts["my_worldscript_name"]._torus) {
            worldScripts["my_worldscript_name"]._torus = player.ship.torusEngaged;
            makeSound = true;
        }
        if (makeSound) {
            var mySound = new SoundSource;
            mySound.sound = "[@click]";
            mySound.loop = false;
            mySound.volume = 1;
            mySound.play();            
        }
    });
}
Obviously, changing "my_worldscript_name" for the actual name of the world script you put the code into (ie the value of "this.name" at the top of the script).

Launch, and press the injectors key. You should hear a beep when you press, and another when you release. Same with torus. And on my system it was instant. As soon as I released the key, there was a beep.

So the documentation, in this case, is fine. But without looking at your code I'm at a loss to explain what's going on. If I'm reading your pseudo-code correctly, you're setting your compass target, engaging injectors, teleporting, then setting a new compass target and having it teleport you without using injectors. Is that correct?
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

phkb wrote: Sat Feb 17, 2024 1:41 am
Obviously, changing "my_worldscript_name" for the actual name of the world script you put the code into (ie the value of "this.name" at the top of the script).
Oi!
phkb wrote: Sat Feb 17, 2024 1:41 am
So the documentation, in this case, is fine.
It's not fine, at all. It's deficient. I never said, nor implied, it was wrong. It is silent on a relevant detail, forcing me into the ritual humiliation of asking a stupid question I shouldn't need to waste your time with. Bad documentation, bad.
phkb wrote: Sat Feb 17, 2024 1:41 am
But without looking at your code I'm at a loss to explain what's going on. If I'm reading your pseudo-code correctly, you're setting your compass target, engaging injectors, teleporting, then setting a new compass target and having it teleport you without using injectors. Is that correct?
It wasn't intended as pseudo-code, just some indenting for emphasis. CODE is the only bbcode that preserves whitespace.

And, yes, that's exactly what's happening. I'll have another bash at it this evening, but don't be surprised if there's a "Do my homework for me" request for you in the morning. :mrgreen:

Thanks for your attention, and the code sample.
User avatar
phkb
Impressively Grand Sub-Admiral
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: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by phkb »

Wildeblood wrote: Sat Feb 17, 2024 3:10 am
Oi!
I wasn't trying to imply that you didn't know this. Sharing code in a public forum means there will be people of all skill levels reading the code, and I was attempting to make my instructions as fool-proof as possible, no matter who might be reading and/or experimenting with the code.
Wildeblood wrote: Sat Feb 17, 2024 3:10 am
but don't be surprised if there's a "Do my homework for me" request for you in the morning.
I don't mind. Happy to help where I can.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

phkb wrote: Sat Feb 17, 2024 3:49 am
I don't mind. Happy to help where I can.
Famous last words. Expect a PM with full OXP, but for future historians reading along: there are two (2) possibilities in play here:-
(1) I've written something incredibly stupid in javascript, and just can't see it, because it's stupid.
(2) Something dumb is happening, and I didn't do it.

Below is actual code, which is called by a timer every 0.5 second. Three variables are:
this._teleportAllowed - Boolean which is always true while ship is in flight.
this._updatedTarget - Boolean has been set true by compassTargetChanged.
this._myButton - string which has been set by player configuration. Current value, confirmed in debug console, is "torusEngaged".

I press the injectors button, NOT the torus button. I get teleported. Do my homework for me, please. Have I simply forgotten how to write a switch?

Code: Select all

    this._monitorState = function () {
        "use strict";
        if (this._teleportAllowed && this._updatedTarget) {
            var ps = player.ship;
            var goNow = false;
            switch (this._myButton) {
              case "torusEngaged":
                if (ps.torusEngaged) {
                    goNow = true;
                    break;
                }
              case "injectorsEngaged":
                if (ps.injectorsEngaged) {
                    goNow = true;
                    break;
                }
              case "alertHostiles":
                if (player.alertHostiles) {
                    goNow = true;
                    break;
                }
              case "alertEnergy":
                if (player.alertEnergy) {
                    goNow = true;
                    break;
                }
              default:
                return; // This should not happen.
            }
            if (goNow) {
                if (this._validTarget && this._validTarget.isValid) {
                    this._updatedTarget = false;
                    player.consoleMessage("Hyperdrive engaged.", 9);
                    ps.position = this._validTarget.position;
                    player.consoleMessage("Arrived at " + this._validTarget.displayName, 9);
                }
            }
        }
    }
P.S. Using January 19, 2024 build of Oolite 1.91.
In your heart, you know it's flat.
User avatar
phkb
Impressively Grand Sub-Admiral
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: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by phkb »

There's a simple error in your code.

Code: Select all

              case "torusEngaged":
                if (ps.torusEngaged) {
                    goNow = true;
                    break;
                }
The reason you're teleporting when hitting injectors is that the "break" command is inside the "if" statement. If should be outside it, like this:

Code: Select all

              case "torusEngaged":
                if (ps.torusEngaged) {
                    goNow = true;
                }
                break;
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

Never mind, I can see it clearly now. Idjat.
In your heart, you know it's flat.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

Bloody hell, that was quick. Yes, I saw it the moment I read my post back. Instantly. But I couldn't see it for hours before that. Incredible.
In your heart, you know it's flat.
User avatar
Cholmondely
Archivist
Archivist
Posts: 5365
Joined: Tue Jul 07, 2020 11:00 am
Location: The Delightful Domains of His Most Britannic Majesty (industrial? agricultural? mainly anything?)
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Cholmondely »

Wildeblood wrote: Sat Feb 17, 2024 11:52 am
Incredible.
At least you can actually see it. I've little idea what any of it means, brackets or not!

If you can improve "Der Dokumentation" please go ahead.
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: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

Cholmondely wrote: Sun Feb 18, 2024 10:42 am
Wildeblood wrote: Sat Feb 17, 2024 11:52 am
Incredible.
At least you can actually see it. I've little idea what any of it means, brackets or not!

If you can improve "Der Dokumentation" please go ahead.
Die Dokumentation. Der Dokumentation is not a thing. Hiran's never going to let you out of that basement.

It was behaving strangely before I put the switch in, actually. So I think my question about the Booleans has merit and was worth asking. The question, put bluntly, was: do the Booleans revert to false when the player releases the key, or a few moments later when the ship's speed reaches normal range? And, if the latter, are those few moments long enough for unintended consequences to occur?

It's just a pity that question can't stand alone, without world+dog pointing and laughing, chanting, "This muppet's forgotten how to write a switch! Switch, switch, burn the witch!"
I can hear them approaching even now.

An event would be more useful than a Boolean:

Code: Select all

this.playerDepressedTorusKey = function (why) {
    if (why !== "They made me, I didn't want to!") {
        player.ship.explode();
    }
}
The whole torus drive & fuel injectors mechanic is a massive cheat anyway, so adding a teleporter to it requires no apology.
User avatar
phkb
Impressively Grand Sub-Admiral
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: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by phkb »

Wildeblood wrote: Sun Feb 18, 2024 12:15 pm
do the Booleans revert to false when the player releases the key, or a few moments later when the ship's speed reaches normal range?
This would only apply to injectors, which are on while you hold down the key. The flag turns to false as soon as you release the key.

For the torus, it has a state that is changed by pressing it's key. So, you press the key (and assuming you are clear to engage it), the torus is on, and it will remain on after the key is released. Press the key again, and the torus is off immediately, which the flag follows, regardless of any slowdown of your ship in progress.

And no one is getting burned. *Way* too many forms to fill in afterwards.
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

phkb wrote: Sun Feb 18, 2024 12:48 pm
Wildeblood wrote: Sun Feb 18, 2024 12:15 pm
do the Booleans revert to false when the player releases the key, or a few moments later when the ship's speed reaches normal range?
This would only apply to injectors, which are on while you hold down the key. The flag turns to false as soon as you release the key.

For the torus, it has a state that is changed by pressing its key. So, you press the key (and assuming you are clear to engage it), the torus is on, and it will remain on after the key is released. Press the key again, and the torus is off immediately, which the flag follows, regardless of any slowdown of your ship in progress.
When I made Bullet Drive, that Boolean didn't exist. Back then we had to compare ps.speed with ps.maxSpeed to infer whether the injectors or torus were in use. So, it's very slightly different, and the fraction of a second while ps.speed > ps.maxSpeed - but still lower than torus speed - could be considered.

You see it's the same. But, different.

When I read about ps.torusEngaged in the Dokumentation, my first thought was that I could make Bullet Drive much simpler now. But in fact, no. It only saves that single calculation where one checks (ps.speed > ps.maxSpeed). Instead, one checks (ps.torusEngaged). Everything else has to remain the same; one still has to faff about with a timer. As I said, an event would have been much more fun.
In your heart, you know it's flat.
User avatar
phkb
Impressively Grand Sub-Admiral
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: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by phkb »

Wildeblood wrote: Sun Feb 18, 2024 1:07 pm
one still has to faff about with a timer.
If you're needing to check anything in *as close to real time as possible*, don't do it in a timer. Use a frame call back. See wiki here: global.addFrameCallback
User avatar
Wildeblood
---- E L I T E ----
---- E L I T E ----
Posts: 2453
Joined: Sat Jun 11, 2011 6:07 am
Location: Western Australia
Contact:

Re: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by Wildeblood »

phkb wrote: Sun Feb 18, 2024 1:15 pm
If you're needing to check anything in *as close to real time as possible*, don't do it in a timer. Use a frame call back. See wiki here: global.addFrameCallback
Oi! I know what a frame call back is. I thought you said no-one was getting burned.

Checking at 0.5 second intervals is perfectly adequate for a teleporter. In Bullet Drive, I used a 0.25 second timer, which is plenty "real time" enough. It takes more than 0.25 second for the torus to get from maxSpeed to 32 x maxSpeed.
User avatar
phkb
Impressively Grand Sub-Admiral
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: p.s.torusEngaged & p.s.injectorsEngaged Booleans

Post by phkb »

Wildeblood wrote: Sun Feb 18, 2024 1:26 pm
I thought you said no-one was getting burned.
That wasn't a burn. That was just a friendly pointer in the off chance you didn't know what one was. I certainly didn't for a long time.

Torus max speed is no longer a constant, by the way. It will keep increasing if no stellar objects (ships, planets, sperm whales, etc) are detected in your path.
Post Reply