Home › Defold › Defold game engine AGENTS.md

Defold game engine AGENTS.md

AGENTS.md for Defold games in Lua: game objects and components, message passing, script lifecycle, and native extensions.

AGENTS.mdDefold

How to use

Save this as AGENTS.md in your repository root, commit it, and your agent will pick it up automatically. Edit the commands to match your project.

AGENTS.mdDownload  
# AGENTS.md: Defold game

## Commands
- Build/run from the editor (Project > Build), or headless with bob: `java -jar bob.jar --variant debug resolve build`
- Lint Lua with `luacheck` if configured.
- Check `game.project` for the Defold version before using new APIs.

## Architecture
- Logic lives in `.script` (game object), `.gui_script` (GUI), and `.render_script` files, plus shared Lua modules (`require "modules.inventory"`).
- Collections compose game objects; spawn dynamic objects with factories (`factory.create("#enemy_factory", pos)`) and collection factories for groups.
- Communicate with message passing: `msg.post("/player#script", "take_damage", { amount = 10 })`, handled in `on_message` by comparing `message_id == hash("take_damage")`. Pre-hash ids at module top (`local TAKE_DAMAGE = hash("take_damage")`).
- Per-instance state lives in `self`; module-level variables are shared by every instance, so use them only for constants.
- Lifecycle: `init`, `update(self, dt)`, `fixed_update` for physics, `on_input`, `final`. Acquire input focus with `msg.post(".", "acquire_input_focus")` and release it in `final`.
- Animate with `go.animate` / `gui.animate` instead of manual tweens in `update`.
- Use `go.property` for tweakable values set in the editor.

## Don't
- Don't edit `.collection`/`.go` text files by hand beyond trivial property changes; describe editor steps instead.
- Don't poll every frame for things messages or callbacks can signal.

## Done
The project builds with bob without errors, and the changed behavior works in a debug build.

More: all Defold rules · all AGENTS.md rules

Related rules

Bevy game engine AGENTS.md

AGENTS.md for Bevy (0.16+) games in Rust: ECS systems, plugins, required components, and fast dev builds.

AGENTS.mdBevy (Rust)

GameMaker GML AGENTS.md

AGENTS.md for GameMaker (2024+ runtime) projects in GML: objects and events, structs and methods, and clean state.

AGENTS.mdGameMaker

Godot 4 GDScript AGENTS.md

AGENTS.md for Godot 4 projects using typed GDScript, signals and scene composition.

AGENTS.mdGodot

MonoGame AGENTS.md

AGENTS.md for 2D/3D games in C# with MonoGame 3.8: game loop, content pipeline, scenes, and allocation-free updates.

AGENTS.mdMonoGame

Pygame (pygame-ce) AGENTS.md

AGENTS.md for 2D games in Python with pygame-ce 2.5+: game loop, scenes, sprites, assets, and testable logic.

AGENTS.mdPygame

Unreal Engine multiplayer AGENTS.md

AGENTS.md for Unreal Engine 5 multiplayer: authority, replication, RPCs, prediction, and testing with multiple clients.

AGENTS.mdUnreal Engine (C++)

Get new rules weekly

One email a week: fresh rule files, agent tips, and what's changing in Cursor, Claude Code and Copilot. Free, unsubscribe anytime.

Opens the Rulestack Newsletter on beehiiv in a new tab. Or subscribe directly on beehiiv.