Best practice for "is game over"-boolean?

Hi,

So I’ve currently have 2 controller-scripts in my game. One for the game level and one for the game board. The controller for the game board handles spawning new pieces and everything else on the board. The game level controller handles updating of scores and such.

Once the game is over, things should happen all over the places and there has to be a flag which says that the game is over.

My first thought is to have it in the game level controller, and the game board controller will look at that flag to check whether the game is over or not.

Is there any best practice for this type of thing?

To be honest, I don’t even know how to access a variable in another script, but I do know about the message layer.

Thank you.

1 Like

It’s probably better to send a message to the board on game over than to probe state variables in another object.

That basically means I will have to have “is_game_over”-flag in each controller?

Well, that depends on what game over means for them and how your design looks.

For a GUI game object it might mean disabling all UI nodes apart from a game over text node. No need to store state for that. Your board might just disable all input, remove all pieces or something like that.

It is often helpful to think about messages as actions rather than as requests to change state. But of course, sometimes you will need to store state.

In this case, it means that the board will let the animations continue, but disable input + and other game elements.

The animations are scripted.

I understand storing state, but storing the same state multiple times?

Ok, so why do game level controller need to store that state?

I suppose I could make it not need it, and let the “game over” menu act only upon messages as well.

I’m not against this, I’m just not used to working with this type of architecture. =)

Yeah, it takes a while to get into it.

1 Like

Thank you for your perspective!

1 Like