[4.5] GetPlayerInput in ACS is not registering

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
User avatar
Zanieon
Posts: 2059
Joined: Tue Jan 13, 2009 4:13 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Somewhere in the future

[4.5] GetPlayerInput in ACS is not registering

Post by Zanieon »

So... i've made a script that needs to register that the player is pressing only the forward key to make it sprint faster after a while, but looks like GetPlayerInput stopped working in 4.5, i tried a couple things before rolling back to 4.4.2 just to make sure and it is indeed something related to the version of the source port.

Literally the examples found in the Wiki can be used to debug this as i used them as well to check if GetPlayerInput is registering any actual key, i used this script to check it out:

Code: Select all

script "ForwardkeyRegister" ENTER
{
    int Buttons;

    While (TRUE)
    {
        Buttons = GetPlayerInput(-1, INPUT_OLDBUTTONS);

        if (Buttons == BT_FORWARD)
        {
            print(s:"You are only pressing the forward key, and no others.");
        }
        Delay(1);
    }
}
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49115
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Graf Zahl »

You cannot run the test like that. The input value contains some bits that may always be set, most importantly one related to the "Run" key. You have to mask out everything unrelated to your test, or you'll get incorrect behavior. This was something that just worked by happenstance in older versions under normal conditions (but more importantly, not *ALL* conditions!) but to allow proper testing of the Run state a new bit was added recently.
User avatar
Zanieon
Posts: 2059
Joined: Tue Jan 13, 2009 4:13 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Somewhere in the future

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Zanieon »

Yeah, i just talked with MarisaKirisame through the Discord server, if this was a longstay bug then alright.

Besides i already found a way to check if the player is only pressing the forward key by comparing only MODINPUT_FORWARDMOVE and MODINPUT_SIDEMOVE values.

In any case, this script is based on an example straight from the Wiki, if this method is now wrong, someone will have to fix that in there too to avoid teaching others the wrong thing.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49115
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Graf Zahl »

This method has always been wrong. You cannot check a single bit in a bit mask like this because the other bits' values may have no relation to what you want to check.
Just because someone put incorrect code on the Wikio does not give the method any official sanctioning.

Where can I find it?
User avatar
Zanieon
Posts: 2059
Joined: Tue Jan 13, 2009 4:13 pm
Graphics Processor: ATI/AMD with Vulkan/Metal Support
Location: Somewhere in the future

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Zanieon »

Here: https://zdoom.org/wiki/GetPlayerInput

It's in the "Reading Buttons" section.

And yeah as i said, if it's a longstay problem i won't shout and complain, i took this as legit method before, but i already managed to find another way so it's all good.

Btw, i think the page is needing an update anyways, because the addition of BT_RUN, which is not there yet.
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49115
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Graf Zahl »

Ok, I removed all bad info from that page. I have to admit I was a bit shocked when I saw that it linked to a decade-old forum thread where Randi, of all people, gave that advice which resulted in the bad examples. :?

Again: No, bit fields do not work like that!
User avatar
Nash
 
 
Posts: 17454
Joined: Mon Oct 27, 2003 12:07 am
Location: Kuala Lumpur, Malaysia

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Nash »

There's a lot of legacy bad advice. For example, I remember waaaay back in the day, being taught that to add flag constants together, to do:

Code: Select all

int flags = FLAG1 + FLAG2;
instead of the proper

Code: Select all

int flags = FLAG1 | FLAG2;
User avatar
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49115
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: [4.5] GetPlayerInput in ACS is not registering

Post by Graf Zahl »

That one's at least harmless as long as each value is a single flag bit.

Return to “Closed Bugs [GZDoom]”