#Score is not updating when emitting a signal by passing an instanciated scene with an Area2D

5 messages · Page 1 of 1 (latest)

limber jacinth
#

I'm currently trying to recreate flappy bird game. I've run into an issue where my score would only update after passing the first set of pipes (part of the main scene and not instanciated). I have an area_shape_entered signal on my pipes script to detect when my player scene enters the area that I set to emit the increase_score signal. Aside from the first set of pipes which are set in the main scene, every pipe after that is instanciated. I know the signal emits since it prints in the console but the score doesn't go past 1.

This is my code to increase the score:
func _on_pipes_increase_score():
var score = 0
score += 1
%PointsText.text = str(score)

stray pumice
#

You have a local variable "score" in _on_pipes_increase_score that you initialize as 0 everytime the function is called, to then increase it by one.
I'm not a mathematician, but according to my calculations, 0 + 1 equals 1 no matter how many times you try. 🙂

limber jacinth
limber jacinth
#

Okay I am wrong about the signal emitting. I moved print('increase_score') over to the main scene inside of the func _on_pipes_increase_score() and it doesn't print. Maybe there's a problem with the signal that I used in the pipes script?

func _on_score_areas_area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
var player_entered = %ScoreAreas.get_overlapping_areas()
if player_entered.size() > 0:
increase_score.emit()