I have a database table that stores basic player data for the game.

It looks like this:

player_id | player_level | player_class_ref | player_exp
    P1            8              W1            68349518
level | required_exp 
  1         100
  8         80000000

The game itself is text and browser based.

I decided to use a rule engine to adjust player data when needed.

It executes after every player event - for example, killing a monster or finishing a quest.

The sample rule looks like this

    player_exp > closest_level_exp
    player_level + 1
    player_exp = abs (closest_level_exp - player_exp)

There might be a lot of similar rules - for example, quest accepting.

So my question is - Is my approach viable for a web and text based game?

I am not sure how such things are usually implemented in games, such rules be hard coded, or they are stored another way?

  • \$\begingroup\$ I'm sorry, but we can't tell you if your approach is viable because we don't know what rules you are going to implement, if they can all be covered by your architecture and how the rest of your architecture looks. You likely don't know that yourself yet. But in the end, always remember that there is no best solution for any given problem. Only the solution which is best for you. \$\endgroup\$
    – Philipp
    Commented Feb 14, 2018 at 13:34

1 Answer 1


I've successfully built a game where the main content and gameplay were implemented via rules similar to this.

It was a visual novel/narrative game where most of the logic hinged on when to trigger particular scenes, so I wanted this to be exposed in data and easy for the narrative designers/writers on my team to control.

I used a fuzzy pattern matching system based on this Valve talk to select the next event to fire.

Each event was a short script (containing dialogue, variable updates, basic conditional logic, or triggers for chaining to the next rule) written in a simple scripting language. The scripts and rules would be compiled to bytecode and run in a fairly basic virtual machine.

This let my core game code stay very lean:

  1. Initialize state variables to new game state

  2. Fire rule matching "new game" event to let writers add to the startup state

  3. Based on the state following the last event, update state variables

    (simple things like advancing a time counter that I might want to happen automatically, rather than write into every single event, or advancing the phase of play between intro - action - result stages)

  4. Look for the next rule to match based on the current state, and fire its event

  5. Loop 3 & 4 until the victory or game over states are hit

This approach gave the writers a ton of flexibility, but also a ton of responsibility to ensure their rules & events supported the game structure & all contingencies. We needed to include a few very permissive rules to ensure the game would never stall with no further matching events to play. And reasoning about the possibility space of the game, or how often/how soon particular scenes might fire became quite complicated.

So far the system has been reasonably successful for its goals, I would say, but it's not a universal solution or ideal for every game.

Based on this, I can say that a rule-matching core works for at least some class of game. Whether it's the right choice for your game is something you'll need to evaluate based on your own plans & goals.


You must log in to answer this question.

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