How to add a star on the level selection based on the scores garnered in the specific level?

Godot Version

Godot 3.6

Question

We’re a 3 member group and complete newbies so our code has been an absolute mess but we made it work somehow. The problem now is, I need to update the level 1/level 2/level 3 button in the level selection scene with a corresponding star based on the score they got in that level

the problem is that, the scores inside that level weren’t made into a separate scene or node, rather, they were tied into the scene’s general code. We usually pass the game files between us so I wasn’t the one who coded this and I don’t know where to begin. The person who coded it is no longer available. Here it is

level 1

Score

var score = 0
var is_reeling = false # Flag to track if the player is reeling in a fish
var fish_scores = {
“Fish”: -4,
“Fish_species_1”: 55,
“Fish_species_2”: 60,

Level 2 & 3

Score

update_score_label()  # Initialize the score display

func update_score_label():
var score_label = get_node(“UI/ScoreLabel”) # Access the ScoreLabel
score_label.text = "Score: " + str(score) # Update the label text

Increase score when a fish is caught

func increase_score(amount):
score += amount
print(“Score increased. New Score:”, score) # Debugging line
update_score_label()

Decrease score (e.g., if a penalty is needed)

func decrease_score(amount):
score -= amount # Subtract from the score
update_score_label() # Update the label with the new score

I have a rough idea on how to update the image level to show the stars, such as loading the resource but the problem is storing the score in that level to retrieve it. I can understand that this is really complicated and messy but I would appreciate if someone could take the time to help us through this :sob:

If you store the score to a singleton, you can access it from any scene.
https://docs.godotengine.org/en/3.6/tutorials/scripting/singletons_autoload.html

1 Like