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

Table-driven behavior

table-driven-behavior.gpc
const uint8 BUTTON_BY_MODE[] = {
    PS5_CROSS,
    PS5_CIRCLE,
    PS5_SQUARE,
    PS5_TRIANGLE
};

const int16 VALUE_BY_MODE[] = { 25, 50, 75, 100 };

int mode;

main {
    if(mode >= 0 && mode < sizeof(BUTTON_BY_MODE)) {
        set_val(BUTTON_BY_MODE[mode], VALUE_BY_MODE[mode]);
    }
}

Tables reduce duplicate switch blocks when the difference is data, not behavior. Choose a switch when each case has genuinely different logic.

Last updated