0 votes

Hello, I am new to Godot and I am making a game for my school project but I cannot get the score to update once I pick up a coin. but once the game ends it will then update how can I solve this?
I have checked multiple resources but none seem to work. Here is my code:

func _on_Area2D_body_entered(body):
     if body.get_name() == "Floor":
          PlayerVariable.Global_enemyScore += PlayerVariable.Global_enemyScore
          var scoreCounter = print("The enemy's score is " + 
     if body.get_name() == "Player":
          PlayerVariable.Global_playerScore += PlayerVariable.Global_playerScore
          ("The player's score is: " + str(PlayerVariable.Global_playerScore))
          PlayerVariable.Global_totalScore = PlayerVariable.Global_playerScore


Also here is my node layout:


Can you help?

asked Apr 24 in Projects by Jakeeee (18 points)

I'm not quite sure that if deleting the node with queue_free () the following lines of code are not executed, but try putting queue_free () as the last statement in the if blocks.
I also see it necessary to put the print in a variable that is only valid inside that if block, simply:
print ("The enemy's score is" + str (PlayerVariable.Global_enemyScore))

1 Answer

0 votes

Try this code$Score_number.text = str(scoreCounter) This should update your Lable,

I try this with method with a button to update a lable to show How much the times I click the button.

answered May 9 by cmk723 (14 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.