Almost all story-driven games require some kind of system to trigger some sort of event for example, dialogs, enemies, or doors opening. Unless the game is very small, you generally don't want to hardcode these. The following recipe will describe a trigger system, which can be used for almost any type of game from FPSs to RTSs and RPGs.
We'll start out by laying the ground work with an AppState controlling all the script objects and the basic functionality of a Trigger
class. Then, we'll look into how to actually activate the trigger and use it for something.
Before we start with the actual implementation, we create a small interface that we will use for various scripting scenarios. We call it ScriptObject
and it should have the following three methods:
void update(float tpf); void trigger(); voidonTrigger();