Skip to content

Add methods to common structs#1097

Open
Sunketchupm wants to merge 8 commits intocoop-deluxe:devfrom
Sunketchupm:dev
Open

Add methods to common structs#1097
Sunketchupm wants to merge 8 commits intocoop-deluxe:devfrom
Sunketchupm:dev

Conversation

@Sunketchupm
Copy link
Copy Markdown
Contributor

@Sunketchupm Sunketchupm commented Jan 29, 2026

I thought of this a while back and figured it shouldn't be too hard to do. It wasn't, thanks to PeachyPeach's efforts for making the ModFS methods work.
Functions that have their first parameter with a struct will be added as a method onto that struct. For example, set_mario_action will be added onto the MarioState struct and, after a bit of name trimming, can be called by instead doing m:set_action.

Most likely there exists some way to make this work well without being this manual, but it's the best I can do with my knowledge.

Test mod:

---@param m MarioState
local function mario_update(m)
    if m.playerIndex ~= 0 then return end

    local obj = obj_get_nearest_object_with_behavior_id(m.marioObj, id_bhvGoomba)
    if obj then
        if obj:check_hitbox_overlap(m.marioObj) then
            m:set_action(ACT_JUMP_KICK, 0)
        end
    end
end

hook_event(HOOK_MARIO_UPDATE, mario_update)

And it works exactly as would with normal function calls

@Sunketchupm Sunketchupm changed the title [WIP] Add methods to common structs Add methods to common structs Mar 7, 2026
@Sunketchupm Sunketchupm marked this pull request as ready for review March 7, 2026 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant