Gamemaker gml

From Mindrally/skills · View interactive version

Gamemaker gml is an AI agent skill from the GitHub repository Mindrally/skills. Best practices for GameMaker Language (GML) development, covering scripts, object events, rooms, data structures, and performance-minded game code. Use when writing GML scripts or object event code in GameMaker Studio, structuring create/step/draw events, managing rooms and instances, building state

How to use this skill

Skill file

GameMaker Language (GML) Development

This skill covers writing maintainable, performant game code in GameMaker Language (GML), including code organization, style conventions, gameplay architecture, and performance patterns specific to GameMaker Studio.

Workflow for Building GML Gameplay Features

  1. Design the object — Decide what Create, Step, Draw, Collision, and Alarm events the object needs, and what data it owns.
  2. Initialize in Create — Set default variable values, instantiate data structures (ds_map, ds_list, structs), and cache references (layer IDs, other instance IDs) in the Create event.
  3. Simulate in Step — Put input handling, physics/movement, state machine transitions, and collision response in Step (or Step-adjacent events like Begin/End Step).
  4. Render in Draw — Keep Draw events limited to rendering; never mutate gameplay state there.
  5. Extract reusable logic into scripts — Move any behavior used by more than one object, or any event body that's grown complex, into a named script/function.
  6. Clean up on Destroy/Room End — Destroy any manually created data structures (ds_list_destroy, etc.) and free surfaces to avoid memory leaks.
  7. Profile before optimizing — Use GameMaker's built-in profiler or manual timing (get_timer()) to find actual hot paths before restructuring for performance.

Code Organization

GML Style

Example: A State Machine with a Script and an Object

// scr_player_states.gml
function player_state_enter(_inst, _state) {
    _inst.state = _state;
    switch (_state) {
        case PlayerState.IDLE:
            _inst.sprite_index = spr_player_idle;
            break;
        case PlayerState.RUN:
            _inst.sprite_index = spr_player_run;
            break;
        case PlayerState.JUMP:
            _inst.sprite_index = spr_player_jump;
            _inst.vspeed = -_inst.jump_force;
            break;
    }
}

function player_state_step(_inst) {
    switch (_inst.state) {
        case PlayerState.IDLE:
            if (_inst.input_x != 0) {
                player_state_enter(_inst, PlayerState.RUN);
            } else if (!_inst.on_ground) {
                player_state_enter(_inst, PlayerState.JUMP);
            }
            break;

        case PlayerState.RUN:
            _inst.hspeed = _inst.input_x * _inst.move_speed;
            if (_inst.input_x == 0) {
                player_state_enter(_inst, PlayerState.IDLE);
            } else if (!_inst.on_ground) {
                player_state_enter(_inst, PlayerState.JUMP);
            }
            break;

        case PlayerState.JUMP:
            _inst.hspeed = _inst.input_x * _inst.move_speed;
            if (_inst.on_ground && _inst.vspeed >= 0) {
                player_state_enter(_inst, PlayerState.IDLE);
            }
            break;
    }
}
// obj_player - Create event
enum PlayerState { IDLE, RUN, JUMP }

move_speed   = 4;
jump_force   = 8;
input_x      = 0;
on_ground    = false;
state        = PlayerState.IDLE;

player_state_enter(id, PlayerState.IDLE);
// obj_player - Step event
input_x = (keyboard_check(vk_right) - keyboard_check(vk_left));
on_ground = place_meeting(x, y + 1, obj_ground);

player_state_step(id);

move_and_collide(hspeed, vspeed, obj_ground);

Gameplay Architecture

Performance

Debugging and Testing

Common Mistakes

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.