Reputation: 46
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
What can I do
Upvotes: 1
Views: 547
Reputation: 700
Maybe you should try something like this:
var is_game_over = false
func game_over():
if not is_game_over:
# your code to add coins etc.
is_game_over = true
First, game_over()
will check if the game's already over (is_game_over
variable), if it's true, it'll do the work and in the end it will set the is_game_over
variable to true
to know that game is already over; and when your player hits the second enemy, the game_over()
function will know that the game is over and won't add coins again.
Upvotes: 1