Spielerando

Lesson 4 of 14Quests that cannot get stuck9 minFree

Quest States in a Game: Not Taken, Active, Done or Failed

A pixel art beekeeper takes two quests from an older beekeeper in a green hat; at the top a log lists them as rows of pictures with counts. She drives off wasps, and each one moves both wasp rows at once; the short one is finished at 2 and the log points at the other. At 3 an exclamation mark appears over the older beekeeper. She picks up a wasp's wing on the way back and hands the quest in.

The blueprint's own five quests. One wasp counts for every quest that wants it. A goal stops at its number, so 3 of 3 never becomes 4. A quest with a hat must be handed in; until then it waits, and the dashed optional goal can still be done. Giving up starts a quest from zero.

Try it: Drive off wasps before you take a quest: nothing counts. Take the wood quest and fetch six logs: it stops at 5. Give up the first quest when it reads 2 of 3: it is back to 0, and the arrow in the log moves to the next quest you are working on.

Keys: ←→ walk Space take, hand in, act X give up a quest

This little game runs this blueprint's tested code in your browser. Nothing you press is sent anywhere. Its code on GitHub.

The game above is the playable demo of our blueprint Quest Log. It runs that blueprint's tested code in your browser.

At every moment a quest is in exactly one state: not taken, in progress, ready to hand in, finished or failed. Each move between them has one cause, and nothing else may make it. The quest log in the game above keeps to this: find each state and move in it with your own hands, then write your quests down the same way before your AI builds them.

Also in this lesson 4 things to read up on 3 questions to check yourself

The idea

A quest starts as a sentence: help the old beekeeper drive the wasps away. But the game asks about it all the time. May the player take it now? Does this wasp count? Is it over, won or lost? A sentence answers none of that. A state does.

The blueprint behind the game above has five. Not taken: nothing counts for the quest. In progress: its goals count. Ready to report: its goals are met, and it waits for the player to come back; only a quest with a hand-in has this state. Finished: it never changes again. Failed: nothing counts for it, and it can be tried again.

Each move has one cause: taking the quest, meeting its goals, handing it in, giving it up, failing it, trying again. The rest of the game only reports what happened, and the quest decides what that means for it. This matters when an AI builds it: a talk starts a quest, an enemy counts for it, a reward closes it, and an AI writes each part on its own. If each part may say "the quest is done", the quest ends whenever the first of them thinks so.

How it works

Play the game above with the buttons listed under it. The log at the top has a row for each quest: its goals with their counts, and a hat on the quests that must be handed in.

  1. Not taken. Before you take anything, walk right and drive off a wasp with the action button. A grey cross shows, and the top row, the long wasp quest, stays grey at 0/3. The blueprint decided that a deed done before taking a quest is lost.
  2. Taken. Walk back to the old beekeeper by the board and press twice. The two wasp quests get their colours, and the arrow points at the long one.
  3. In progress. Drive off wasps. Each one moves both rows. The short quest needs 2 and has no hat, so at 2 it is finished at once, with a star. The long one needs 3 and is still in progress.
  4. Ready to report. At 3 of 3 the top row turns yellow and an exclamation mark appears over the old beekeeper: the hat means it waits for a hand-in. Until then the dashed goal, a lost wing in the grass, still counts.
  5. Finished. Hand it in at the board. It gets its star, the arrow moves on to a quest still in progress or goes away, and a moment later the meadow starts over.
  6. Given up. In the next round, press the other button when the long wasp quest reads 2 of 3. It is back to not taken, at zero.

Now write it as a table, each state with the moves that leave it:

The gaps are rules too: no line leads from not taken to finished, and nothing leaves finished. The blueprint's diagram has one more arrow, from not taken to ready, for games that keep the progress of a quest given up; at its own setting, used above, a quest always starts at zero.

What goes wrong

The shortcut is one yes-or-no flag, "quest done", that any part of the game may set. It is the shortest code, and an AI with no table to keep to is free to write it: the flag is set when the count reaches three, in the old beekeeper's thank-you line, in the code that pays the reward.

Each place works when the quest is played the way it was written. Then a player tries another order. She drives off three wasps on her way to the board, and the quest is done the moment she takes it, or shows as done although she never took it. She talks to the old beekeeper after the quest failed, and the thank-you line sets it to done. The reward is paid wherever the flag is set, so it can be paid twice. And a flag knows only yes and no: a failed quest looks like one nobody offered, and "ready to report" cannot be said at all, so the wing that would have counted is lost.

One question finds it before anyone plays: which lines of the code may change this quest's state? More than one function means you have the flag. In play, do what the table forbids: the deed before the quest, the talk after the end, the hand-in twice.

A quest can also be finished the moment it is taken when its list of goals is empty, because "every goal is met" is true of an empty list. Our page on that symptom, in the reading list, has the test for it.

Tell your AI

I want my quests to be states with moves, not one flag that says "done". Do not write any code yet.

1. For every quest in my game [name them, or read them from my files], write a table: its states (not taken, in progress, ready to hand in if it has a hand-in, finished, failed), every move between them, and the one cause of each move.
2. Mark the moves that must not exist: nothing leaves "finished", and nothing goes from "not taken" straight to "finished". Tell me whether a deed the player does before taking a quest counts or is lost. If I have not decided it, ask me.
3. Plan one function as the only place that changes a quest's state. Search my code and list every other line that sets a quest's state or a "done" flag, with its file. That list must end up empty.
4. Then build it, with one test for every move in the table and one for every move that must be refused: a deed before taking the quest changes nothing, a quest with no goals is not finished when it is taken, a finished quest stays finished. Run the tests and paste me their real output, not your summary.

Try it

Read up

Where to go deeper: the pages of ours this lesson builds on, and what others have written about its point.

Check yourself: three questions

Each answer is checked and explained at once. The questions are part of the quiz, so they count for your Game Coder IQ like any other.

Question 1 of 3Easy

In the game above, the player drives off a wasp before she has taken any quest. Then she takes the long wasp quest. What does its row show?

All questions of this course · The quiz and the Game Coder IQ

Next lesson Quest Items and Soft Locks: What the Story Needs Later

How useful was this page?

Nobody has rated this page yet.

One click, no account. It tells us which pages to make better next.

Last updated: 2026-11-27