I'm making an adventure game set in a school (think Bully, but much less scope as I am one person) and I'm starting to program the last important systems like a sound manager and an event system and I'm a bit confused about the event system.

Basically, I want to be able to track stuff like missions completed that may cause some stuff to happen like changing dialogue of a character. One other example is that talking to one character before another will cause you to interact with them differently. I don't want to handle this kind of stuff for each indivdual NPC, especially since each NPC has one script that holds stuff like their current dialogue and other important data.

Another thing in my game is that the time is based on periods rather than a real-time system. Every time you complete a mission or some other event, it will change (the periods are Morning, Afternoon, Evening, and Midnight), which also changes the position of NPCs and may also change their dialogue.

How would I design such a system?


1 Answer 1


Most games handle this with a large array of boolean (in some cases integer) story flags.

Your dialogue system should be able to check these flags and trigger different dialogue lines depending on whether or not certain flags are set.

Example: When the player completed Quest X, you set QUEST_X_COMPLETED to true. When the player completed this quest with the evil choice, you also set QUEST_X_EVIL to true. But when the player completed this quest with the good choice, you instead set QUEST_X_GOOD to true.

Now the NPC involved in that quest would check those flags. If QUEST_X_COMPLETED is false, they tell the player to complete Quest X already. When it is true, it thanks the player for completing Quest X. When QUEST_X_EVIL is set, they then call out the player for being such a meanie. When QUEST_X_GOOD is set, they then call out the player for being such a wuss.

You might also need a system which allows you to use story flags to decide whether or not certain objects in the game appear at all. So certain objects will only be there when the story requires them to be there. Is your game one scene of many scenes? When your game has many scenes and the player frequently switches between them, then it might be sufficient to have a script which checks the story flag for that object in Start() and then calls SetActive(false) when the required flag isn't set. But if you require that certain objects appear immediately within the same scene when a certain flag is set, then you might require a separate controller object which takes care of monitoring story flags and activate game objects as soon as their spawn conditions are met.

The current time of day should also be a set of story flags. So you can use the same system to check flags like TIME_IS_MORNING or TIME_IS_EVENING in your story system and your game object activate/deactivate system.

(By the way: It's fortunate that you want a system where time advances only at predictable moments and not a real-time daycycle where the time period can change at any time. Because with a real-time system you would have to find a solution to what happens when an NPC is supposed to spawn/despawn while the player sees or even interacts with it. Such a game mechanic can get really glitchy if you don't remember to think of all the edge-cases)

  • \$\begingroup\$ I'm timid about a flag system that NPCs check because, as mentioned, I have all NPCs sharing on script (around 40 characters, don't want to write an indivdual script for each of them). Although, I do have my own custom node-based dialogue system (think value brand Fungus) that I can maybe utilize for this, though. \$\endgroup\$ Commented Feb 28, 2020 at 23:49
  • \$\begingroup\$ @Ducktor While I don't think it's a good idea to have all NPCs share the same script, I don't see why this architecture prevents a flag system. If anything, it makes it easier to implement one, because you have one script which knows all the NPCs and can also hold all the story flags. \$\endgroup\$
    – Philipp
    Commented Feb 29, 2020 at 9:59
  • 1
    \$\begingroup\$ Well my dialogue system can just be used for doing this instead of inside the NPC script (my dialogue system now supports branch nodes which can check for state flags and then do stuff based on that) \$\endgroup\$ Commented Feb 29, 2020 at 15:02

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .