A worker keeps walking to a building that no longer exists
Fields get cut, mines run dry and houses burn while a worker is on the way there. If the job is stored only as a pointer, the worker stands at an empty spot or crashes the game. This entry shows how to check a job and where the worker should turn next.
Why this works
A job named by a pointer can disappear while someone is walking to it, so the worker must keep checking that the target still exists and is the right kind. When it does not, the worker turns to the nearest other one, and ties are settled the same way every time.
When not to use it
Skip it when the player assigns workers by hand and wants them to stay put, even if the target is gone. Then stop them and say so, since a worker who wanders off on its own can feel like losing control.
In the full entry
- What to build, step by step
- Starting values and the reason for each
- 3 common mistakes and the fix
- A diagram of every state
- 34 lines of example code with 3 checks that pass
- How your AI shows you that it works
Say this to your AI
Use the Spielerando entry "A worker keeps walking to a building that no longer exists" (read_entry worker-target-destroyed-reassign) in my game. Build it step by step, and show me how you checked that it works.Or skip this and connect the MCP: your AI then finds all of this by itself.Connect the MCP