jperezdelreal/firstframestudios/state-machine-patterns
Claude Code and agent skill by jperezdelreal/firstframestudios
- community
Checking that the SKILL.md file is still in the repository.
Robust state machine design — exit paths, transition guards, timeout safety nets, and common anti-patterns
Install
npx vskill@latest install jperezdelreal/firstframestudios/state-machine-patternsSKILL.md
The same SKILL.md was published earlier as jperezdelreal/firstframestudios/state-machine-patterns.
Context
Robust state machine design for game entities, distilled from critical bugs in firstPunch (player freeze, enemy passivity, timer conflation). Apply when implementing, debugging, or reviewing entity state machines for players, enemies, bosses, or NPCs. Not applicable to UI framework state or simple on/off toggles.
Core Patterns
Every State Must Have an Exit Path
Before adding any state, answer: "How does the entity leave this state?" If you can't answer in one sentence, the state is broken. Document states using a transition table with Entry Condition, Per-Frame Behavior, and Exit Path(s) — empty exit cells indicate dead-ends.
Guard Conditions on Transitions
Not every transition is valid from every state. Maintain an actionableStates list for input-driven transitions and a protectedStates list (e.g., 'attack', 'windup', 'hit') that are immune to AI/external override.
Timeout Safety Nets
Every timed state needs a maximum duration fallback. Recommended maximums: attack 2.0s, hitstun 1.0s, grab 1.5s, dodge 0.5s, invulnerable 3.0s, boss_transition 5.0s. Only idle, walk, dead are intentionally unbounded.
Separate Timers for Separate Concerns
Never use one timer for multiple purposes (attack duration AND cooldown AND AI delay). Each concern gets its own timer variable to prevent state corruption.
Single Point of State Change
Route all state changes through a single setState() method with guards. Multiple systems (input, AI, animation) writing this.state directly causes same-frame conflicts.
Key Examples
Dead-end state (player freeze bug):
Unguarded AI override (enemy passivity bug):
Anti-Patterns
- Dead-end states — No exit path; entity enters and never leaves. Highest-severity bug class.
- Timer conflation — One timer for multiple concerns causes state corruption (1-frame attacks, hitbox inversion).
- Unguarded state override — AI/input sets state without checking protected states.
- Missing negative code — Bug is in code that doesn't exist (missing exit transition). Only found by tracing execution, not reading.
- Distance threshold dead zones — Non-overlapping approach/attack ranges create indecision zones.
- Testing by reading, not tracing — Always simulate 3-5 consecutive frames mentally; reading
ifconditions looks correct but hides timing bugs.
Checklist
- [ ] New state has documented exit path reachable within 60 frames
- [ ] Timeout safety net exists for all timed states (max 5s)
- [ ] Protected states list updated for animation-critical states
- [ ] No timer serves double duty
- [ ] Transition table updated; no empty exit cells
- [ ] No code path sets state without guards
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryChecking.squad/skills/state-machine-patterns/SKILL.md
Popularity
- Repository stars
- 1
- 7-day trend score
- 0
Stars and forks are for the whole GitHub repository, not this skill alone. Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/jperezdelreal/firstframestudios/state-machine-patterns)