Godot Version
4.2.2
Question
Hello all,
I would appreciate your input on resolving this little pickle I’m in, detailed below.
The requirement is to increment the Player “Lives” variable by 1 for every 200 points the player accumulates.
The following is what I have implemented so far. (Only the coding parts relevant to the issue are mentioned here.)
Signal Manager (Autoload singleton) - Manages all the signals in the game
extends Node
signal add_one_life
Score Manager (Autoload singleton) - Manages updating score, highscore, etc.
extends Node
var current_score: int = 0
func update_score(points: int)-> void:
current_score += points
if high_score < current_score:
high_score = current_score
if current_score % 200 == 0:
Signalmanager.add_one_life.emit()
Signalmanager.current_score_update.emit()
Player script
extends CharacterBody2D
var current_score: int #Starts at 0 on load.
func _ready():
Signalmanager.add_one_life.connect(add_lives)
func add_lives():
current_lives += 1
Signalmanager.current_lives.emit(current_lives)
The above configuration works if the current score ends up as precisely multiples of 200. (Ex: 200, 400, etc.)
Ex:
If the current score is 50 and the player collects 150, the new score of 200 would add one life.
But if the current score is 100 and the player collects 150 points, the new score of 250 would NOT increment the life variable by 1, despite the current score passing the 200-point threshold.
Your help is much appreciated.
Thank you in advance!