I hope that I'm posting this correctly as I'm new to the site, feel free to correct me if I'm in the wrong spot.

As for my issue: I'm working on an 2D side-scrolling platformer game in libGDX, and I've run into an issue that I've considered before but never received a solid answer. Here's an example of what I'm wondering about: In games like, say, the Legend of Zelda, when the player steps on a switch, or catches a torch on fire, this can open a door or release a monster or cause a myriad of other things to happen.

Now, I imagine that this utilizes some sort of Event-trigger relationship or messaging system, but it seems that it would be insane to hardcode all of these events into the game engine itself, even when utilizing an event-based system.

The same goes for tutorial and dialog systems: the player interacts with an NPC, or some sort of in-game object, and the dialog/tutorial continues at certain points.

In my game, I will specifically need to be able to have events triggered after a character does a certain thing, and I will need to be able to have series of dialogues triggered. I think that I know how I could hardcode these things, but I'm going to have numerous levels that I wish to develop with a level editor such as Tiled, instead of hardcoding them. Because of this, I don't know how I would integrate events into such a system.

My questions are: what do game programmers do to avoid hardcoding these things into their games? With something like a massive quest system with tons of dialog, or numerous levels with switches and events to trigger, how are these integrated into the game?

Thank you for any answer you can give me, I'm really stumped on this one :)

P.S. If you need any more clarity on what I'm asking for, please tell me so I can give more detail if needed.

P.P.S I saw this post Level editor event system, how to translate event to game action but I've seen on other pages that people go back and forth on whether to use a scripting language, or some sort of file format like XML or JSON, and it's very confusing...

  • \$\begingroup\$ Try posting this on reddit \$\endgroup\$ Commented Aug 29, 2015 at 15:54
  • \$\begingroup\$ No response on reddit, either. I guess I will have to uber-google this one \$\endgroup\$
    – Dibz
    Commented Sep 2, 2015 at 17:57
  • \$\begingroup\$ If I find an answer or develop my own fix I will put it as an answer \$\endgroup\$
    – Dibz
    Commented Sep 9, 2015 at 23:16

1 Answer 1


Well, you have to essentially make your engine able to load logic from disk somehow. You could actually code that into your program, but more often people devise a data file format for these purposes.

What in end effect it boils down to is creating a very simple (and not necessarily turing-complete, and not necessarily text-form) programming language. That's why so many game developers just use a scripting language like Lua.

But what you really only need is to build the basic operations into your engine (e.g. spawn a monster, despawn a monster, show a dialog tree, move a monster, add a mission objective, resolve mission, whatever your game requires). Then you give each situation an event or trigger (like "monster killed" or "player inside" or "dialog choice selected").

Then build a data structure that can be used to describe each basic operation. In your on-disk representation of a level, save such a data structure for each event of every object. Whenever an event happens, load the data structure (probably an array of 'em) and do the things it describes.

Many games can get away with this. Some also need some sort of counter variables (plus increment/decrement commands), and maybe a conditional (easiest way to implement: Just give it a variable and a value to check it against, then have it trigger another event). If you're going beyond that, you might probably as well use a real scripting language.

What you save the data structure as in the end doesn't really matter. You can use XML, stick it line-wise in text files, build a binary data structure, whatever you want.

Your data structure can be as easy as an int to describe the operation (i.e. 1 = spawn monster, 2 is despawn etc.), and two strings naming which objects to operate on.

  • \$\begingroup\$ For an excellent example, look at Paradox Interactive games and their custom event system. \$\endgroup\$
    – Jax
    Commented Dec 7, 2016 at 16:07

You must log in to answer this question.

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