Topic was automatically imported from the old Question2Answer platform.
Asked By
Titox
So I had a node with area_2d enemies. When a player hits any of the enemies, the on_enemy_area_entered signal calls the game over function which adds the coins collected during that game instance to the global coin variable and saves it. Nice and dandy…except if the player hits both at the same time. When that happens, the signal calls the game_over function twice and therefore the player sees double of his real score in the main menu…Due to the type of game it is I cannot prevent the player from hitting two enemies at the same time
In the script that has the game_over function, add a boolean member variable to remember what state the game is. So if game_over is called a second time, you can ignore the second call.
var game_is_over = false
func game_over():
if not game_is_over:
game_is_over = true
# Execute game over logic
Don’t forget to reset the variable when starting a new game (you won’t need to if you re-instance that scene, depends on your game).