For the complete documentation index, see llms.txt. This page is also available as Markdown.

Toggle state without repeat firing

Do not toggle from a held-value check; it would flip on every cycle:

Why this matters

get_val returns a value every single VM cycle. If you toggle based on whether a button is currently held down, your toggle flips on every cycle the button is pressed — which means dozens of flips per second. From the outside it looks random: sometimes the toggle ends up on, sometimes off, depending on exactly when you release the button.

The fix is to only toggle when the button is first pressed, not while it stays held.


The wrong way

Do not toggle from a held-value check; it would flip on every cycle:

int enabled;

main {
    if(get_val(PS5_CROSS)) {
        enabled = !enabled;
    }
}

Every cycle where CROSS is held, enabled flips. Hold CROSS for half a second and you get an unpredictable final state.

The right way

Use event_press, which is only true on the exact cycle the button changes from released to pressed:

Now one press equals one toggle, no matter how long CROSS is held.


Quick rule

  • get_valis the button pressed right now?

  • event_pressdid the button just get pressed this cycle?

Use get_val when you want continuous action while a button is held. Use event_press when you want a one-shot reaction to a press.

Last updated