Hey, this thing just happened, do you care?

Pretty much sums up what an event system does. 

I was unfortunately unaware of this programming delicacy at the time that I'd created the character controller that I'm working on for Ball Star Battle. However, that doesn't stop this amazing piece of code from saving me spaghetti cooking time in the future. Here's an example of how it's done in C++.

void Physics::updateEntity(Entity& entity)


bool wasOnSurface = entity.isOnSurface();



if (wasOnSurface && !entity.isOnSurface())


notify(entity, EVENT_START_FALL);



Example of starting an event in C++ (Nystrom, R. 2014)

The code above is a short example of an entity essentially yelling out that it's falling. Once an entity has invoked and event, optimally via an event manager, the event manager will then notify anyone that cares about that particular entity falling that the entity is falling. The entities that care are called observers, and they do with the information given to them according to the way that they want to. 

A prime example of an entity invoking an event would be unlocking achievements. A player might be sending out a lot of events for an event manager to give to other scripts throughout the game, when the player completes a particular action, the player might then invoke an event that only the achievement script is listening to, which would then go ahead to unlock the achievement. The information that the player sends when that particular event is unlocked might be expanded to include the system's date and time which can then be utilised by the achievement script to show when the player unlocked the achievement to the outside world. This system is used in contemporary games and consoles.

Invoking events is a very simple, clean and easy way to pass information around multiple scripts, having certain scripts listen out for events and then proceeding to do what they want with the information provided in the event can certainly pull a great weight off of my shoulders when it comes to making my general coding skills better. I plan to incorporate this pattern into Ball Star Battle, so that I can get a clear idea of how and when to implement it properly.

In fact, with the help of others, I've begun implementing event into my game, the script for my event manager may be found here.


Tylah Kapa