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

Event-driven input routing

Read only the controls owned by the active state. A small event router is easier to audit than several unrelated blocks that can all mutate the same menu state:

event-driven-router.gpc
main {
    if(event_press(PS5_UP))         handle_up();
    else if(event_press(PS5_DOWN))  handle_down();
    else if(event_press(PS5_LEFT))  handle_left();
    else if(event_press(PS5_RIGHT)) handle_right();
}

function handle_up()    { set_val(TRACE_1, 1); }
function handle_down()  { set_val(TRACE_1, 2); }
function handle_left()  { set_val(TRACE_1, 3); }
function handle_right() { set_val(TRACE_1, 4); }

Use separate if statements instead when simultaneous directions intentionally need separate actions. Analog magnitude still requires an ordinary input read such as get_ival.

Last updated