For example, I have a Game class and it keeps an intint that tracks the playersplayer's lives. I have a
if ( mLives < 1 ) conditional
check and inside the if scope it does some work.
if ( mLives < 1 ) { // Do some work. } However this condition keeps firing and the work is done over and over, so forrepeatedly. For example i, I want to set a timer to exit the game in 5 seconds. It Currently, it will keep setting it to 5 seconds every frame and the game will never endends.
This is just one example, and I have the same problem repeats itself over and over in several areas of my game,. I want to check for some condition and then do something once and only once, and then not check or do the code in the if statement-statement again. Some possible solutions that come to mind are having a boolbool for each condition and set the boolbool when the condition fires, however. However in practice this gets very messy handling lots of bools thatbools, since they have to be stored in aas class fieldfields, or even statically within the method itself, that would get nasty fast.
What is the proper solution to this? ( Notnot for my example, but for the problem domain )? How would you do this in a game?