Your first stateful script
int enabled;
main {
if(event_press(PS5_CROSS)) {
enabled = !enabled;
}
if(enabled) {
set_val(PS5_R1, 100);
}
}This introduces the four ideas used by almost every real script:
Element
Description
int enabled;
Declares a global signed 32-bit runtime variable. It starts at 0.
event_press
Is true for the cycle in which the input transitions from released to pressed.
!enabled
Changes zero to one and any nonzero value to zero.
State
State set in one cycle remains available in later cycles until the script reloads or code changes it.
Last updated

