The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

Hi, I´m making a pong game and I have a problem with the HUD, the HUD it´s made from a canvas layer with 2 Labels and the problem is that points get subtract or attribute to the wrong player on occasions (like 1 or 2 times and a playthrough) then works fine, the points are attributed using signals and area2D, this is the code of the HUD:

extends CanvasLayer


var score_1 = 0
var score_2 = 0

func _ready():
    pass
func update_score():
    $Score_1.text = str(score_1)
    $Score_2.text = str(score_2)
func _on_Meta_1_body_entered(_body):
    update_score()
    score_1 += 1
func _on_Meta_2_body_entered(_body):
    update_score()
    score_2 += 1
in Engine by (16 points)

1 Answer

+1 vote

I think you should call the update_score function after you add the 1 to the score. Otherwise it will show the score increase the last time the score was updated instead of the current time.

by (8,550 points)

thanks, that solve the problem

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 Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.