NPC Brain: A Coroutine State Machine
Give an enemy a memory that survives between game ticks using coroutines, so its patrol-and-chase brain pauses and resumes like a tiny thread.
What you'll be able to build
Give an enemy a memory that survives between game ticks using coroutines, so its patrol-and-chase brain pauses and resumes like a tiny thread. Along the way you pick up real, transferable Lua skills, not just this one project:
- coroutine.wrap and yielding values
- resuming a coroutine with new input each tick
- modeling persistent state without globals
- closures capturing local state
- string.format for tick reporting
- ipairs over a timeline of events
A course like this one
Yours is built from your own placement, so module count and depth will differ. This map shows what a advanced-level Lua learner building NPC Brain actually gets.
- Module 1: Idiomatic Lua and string patterns5 lessons
Builds the production-ready version of the script for your npc brain.
- Module 2: Closures, upvalues, and varargs5 lessons
Builds the production-ready version of the reusable module for your npc brain.
- Module 3: Metatables, OOP, and coroutine schedulers5 lessons
Builds the production-ready version of the metatable behaviour for your npc brain.
- Module 4: Sets, lookups, and sparse tables5 lessons
Builds the production-ready version of the table model workflow for your npc brain.
- Module 5: Iterators and stateful loops5 lessons
Builds the production-ready version of the function that powers your npc brain.
- Module 6: Sandboxing and production hardening3 lessons
Builds the production-ready version of the release package for your npc brain.
How the lessons actually work
Every lesson has you predict what a piece of Lua code will output before you run it, then run it for real in your browser and fix what you got wrong. Each module ends in a challenge gate with hidden tests, so you can't advance until your code actually works. The course closes with a capstone that assembles everything into NPC Brain, and a runnable proof page tied to your own code.
Common questions
How long does the NPC Brain: A Coroutine State Machine course take?
about 7 hours, across 6 modules and 28 lessons, at roughly 15 minutes per lesson. Your own course may run shorter or longer, since it's sized to your placement result, not a fixed template.
Do I need experience?
Yes. This is an advanced-tier Lua project, so it assumes you're already comfortable writing and reading Lua before you start.
How much does it cost?
$15 one-time, no subscription. The first module is free, so you can see exactly how the course teaches before you pay for the rest.