Detectors using Finite State Machines

Finite State Machines can be easily used to detect a sequence of events occurring. It's actually one of the main uses for them in the real world. In the context of a Visual Novel this can be useful for having NPCs react to things the player does in the game. It can also be useful for having one NPC react to things another does.

Example Scenario

Anne is an NPC that is concerned about her friend Beth. If she spots the player going out with Beth a couple of times, and then sees the player going out with someone else, the next time she sees the player dating Beth she will have words! For this example if a week goes by without anything happening Anne will forget what just happened. Drawing out the state diagram gives something like this:

Anne's detector state diagram