Overview
Actions are deterministic operations that modify game state. They’re the primary way to handle:- Player input (keyboard, mouse, touch)
- Scheduled events
- Network messages
- AI decisions
Action Structure
An action is a function with typed parameters:params- Typed parameters passed to the actionentity- Entity the action is invoked onworld- The game worldplayer- Player who triggered the actioncharacter- Character controlled by the playeroffline- Whether action is running offline
Creating Actions
Action Patterns
Movement Actions
core/src/ecs/actions/movement/Move.ts
Attack Actions
core/src/ecs/actions/attacks/Dagger.ts
Interactive Actions
core/src/ecs/actions/interactive/Eat.ts
Building Actions
core/src/ecs/actions/interactive/Place.ts
Input Mapping
Map keyboard/mouse/gamepad input to actions using the Input component:core/src/games/build/Bob.ts
world- Game worldclient- Client instancecharacter- Controlled characterplayer- Player entityaim- Current aim direction (XY)target- DOM element clickedhold- Number of ticks key has been held
Action Queue
Actions are queued and executed deterministically:Input Maps
Reusable input configurations:core/src/ecs/actions/movement/WASDInputMap.ts
Player Actions
Actions that operate on player entities:core/src/ecs/actions/PlayerActions.ts
Command Actions
Global actions that don’t target a specific entity:Best Practices
Deterministic
Actions must produce the same result given the same input. Avoid random numbers without seeding.
Validate input
Check that entity and components exist before using them.
Use params
Pass data through params rather than capturing variables from closure.
Queue properly
Always queue actions for tick + 1 or later, never for the current tick.
Performance Tips
Batch actions
Batch actions
Throttle expensive actions
Throttle expensive actions
Early exit checks
Early exit checks
Next Steps
Components
Learn about component data structures
Systems
Process actions with systems
UI
Create interactive UI elements