gamemaker gml
via PatrickJS/awesome-cursorrules
GameMaker Language rules for organized, performant game code across objects, events, and data structures.
What is gamemaker gml?
Establishes conventions for GML code organization, style, gameplay architecture, and performance optimization. Use this rule when building GameMaker projects to maintain clean separation of concerns, avoid common pitfalls, and keep hot-path code efficient.
- Enforce object event responsibility separation (Create, Step, Draw) and move reusable behavior into scripts and functions
- Establish naming conventions, variable scoping, and use of constants, enums, and macros for identifiers and state management
- Guide finite state machine patterns for player, enemy, UI, and game-flow logic with explicit input/action separation
- Identify performance bottlenecks: avoid broad instance searches, cache asset/layer IDs, pool frequent allocations, and profile before optimizing
- Prevent common mistakes: no game logic in Draw, explicit data structure cleanup, guard optional references, avoid magic numeric state IDs
Applies to
File patterns this rule matches.
Rule definition (reference)
Source of truth, from the repository.
GameMaker GML Rules
Code Organization
- Keep object event code short and move reusable behavior into scripts or functions.
- Use clear prefixes or naming conventions for scripts, objects, sprites, rooms, and globals.
- Prefer functions over copy-pasted event blocks.
- Keep create-step-draw responsibilities separate.
- Put initialization in Create, simulation in Step, and rendering-only work in Draw.
GML Style
- Use descriptive variable names and avoid one-letter names outside small loops.
- Prefer local variables with
varor function-scoped declarations over unnecessary instance variables. - Use constants, enums, and macros for repeated identifiers, layer names, states, and collision groups.
- Guard optional instance references with
instance_exists. - Keep global state minimal and document it.
Gameplay Architecture
- Use finite state machines for player, enemy, UI, and game-flow states.
- Keep collision logic explicit and deterministic.
- Separate input collection from action execution.
- Use alarms, timelines, or explicit timers consistently; do not mix patterns without reason.
- Store save data through structured maps/structs and version the save format.
Performance
- Avoid expensive searches such as broad
instance_findor repeated collision scans in every Step event. - Cache frequently used asset IDs, layer IDs, and object references when safe.
- Destroy data structures when no longer needed.
- Use object pooling for frequent projectiles, particles, or short-lived effects when allocation becomes costly.
- Profile before optimizing and keep hot-path code simple.
Debugging and Testing
- Add debug overlays for collision boxes, state, velocity, and AI decisions when useful.
- Use assertions or explicit guard clauses for impossible states.
- Test room transitions, pause/resume, save/load, and controller/keyboard input separately.
- Keep reproducible test rooms for complex mechanics.
Common Mistakes
- Do not put game logic in Draw events.
- Do not create data structures without destroying them.
- Do not rely on room editor instance order for critical behavior.
- Do not hardcode magic numeric state IDs.
Related rules
Senior full-stack TypeScript, React, Node.js guidance with clean architecture, testing, and WHY-oriented reasoning.
Quantitative factor research skills for designing, evaluating, and mining alpha factors in equities markets.
Android development with Jetpack Compose, clean architecture, and Material Design 3.
Angular development with Novo Elements UI library using standalone components.
Expert Angular 18 + TypeScript development with Jest, emphasizing clean code and performance.
Manage Kubernetes clusters, add-ons, stacks, and credentials via the Ankra CLI platform.