Data-driven and Game Logic

posted in Event-driven engine for project Hangman
Published August 08, 2021
Advertisement

In last post of my blog Event-driven engine https://www.gamedev.net/manage/blogs/5858/​ I talked about the magic numbers and ways to extract them from the code. Also for any hard-coded data inside the code like the Strings.

But that is not enough in our data-driven way. There is still hard-coded elements inside our code… The Game Logic

This is the hardest part, let discuss some examples in the code

	// Initial Scene
	hangman.generateNewWord();
	hangman.startAnimation("game");
	lifes.getComponent(ImageAtlas.class).setIndex(hangman.getAnimationID());	
	textBox.getComponent(Text.class).clear();
	textBox.getComponent(Text.class).appendLine(hangman.getHeaderString());
	textBox.getComponent(Text.class).appendLine(hangman.getCurrentRevealedWord());

In order to create the first state of the scene, the hangman component that contains the methods related with the specific game “hangman” needs to share information with UI components: lifes, is the hangman picture; and textBox, displays the word and the updates.
Every time that players presses a new key, hangman object checks if it is a match or not and the UI objects are updated.
It is very simple, because there are only three entities but it shows how the relationships between them are hard-coded.

If I want to add another TextBox entity to display the letters that you have already pressed, to keep the word and the pressed keys separated, I will need to change the code. As I said, it is easier to re-code the program than all the activities needed to prepare a data-driven logic, but with hundreds and hundreds of entities a data-driven approach is much better.

Usually, the engines let you code the logic in an easier way:

  • Scripting languages → you code in another language or custom language the logic (the glue between your entities-components).
  • Graphical tools → let you do some predefined event/actions with the entities-components.
  • Events → Event-driven design
  • Other options that I'm till not aware or not come to my mind at this moment ?

Of course, I'll choose Events!!!

Because they are the title of the blog. And I don't need to create another language to do things that I already know how to do in Java.
About the graphical tools, they could be added on top of your event system.

All the engines use events/triggers at least for the UI

“…when this happens, do that…”

  • This is an example in Scratch.

  • RPG Maker lets you add events and actions associated with them.

“when player reach position x,y → show text”
“when player reach position x,y → teleport to different scene/position”

  • Other tools let you code graphically, like Unreal BluePrints. I watched several videos about BluePrints and the central object is the function.
    A functions needs two inputs, 1 event and 1 entity/component. The function applies the actions to the component when the event is triggered, and fires another event that could be followed by more actions/functions….


In this example, when event “BeginPlay” is triggered, the function “Toggle Visibility” modifies the entity-component PointLight-LightComponent, On the right, the output event is not linked to any further action.

The logic of the application is the graph, if you change the graph, you change the behavior.

They are data-driven because the code does not include any logic, they are just a bunch of functions and classes. The logic is provided by the graph…

Usually, they let you create more event type and functions with your custom code, that is automatically imported in the graphical tool.

Anyway, some engines hard-code all your logic when they build the application, for performance reasons.


In next post, I will talk about EPC Event-driven Processing Chain.

0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement