Toggle state without repeat firing
Last updated
Do not toggle from a held-value check; it would flip on every cycle:
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.
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.
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.
get_val → is the button pressed right now?
event_press → did 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
int enabled;
main {
if(event_press(PS5_CROSS)) {
enabled = !enabled;
}
}
