Problems with setting a score on a 2D game

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Gisore

Something’s wrong with my script.
i have 2 labels “Score” and “Lost Balls” on this project, somehow i got the func working with “Score” but “Lost Balls” would aways change the score to 1
goes like this:

    extends Node2D
var score = 0 setget set_score
var balls = 0 setget set_score

func set_score(value):
	score = value
	get_node("Score").set_text("Score: "+str(score))
	
func set_bolas(value):
	bolas = value
	get_node("Balls").set_text("LostBalls: "+str(balls))

thats for the World Node script
and theres for the “Ball” node:

Working part (score)
		if body.is_in_group("Brick"):
			get_node("/root/World").score+= 1
			body.queue_free()

and theres:

Probably wrong part (balls)
	if get_position().y > 360:
		get_node("/root/World").balls+= 1
		queue_free()

Not sure how to set a Spoiler Tag, but here’s the full code:

extends RigidBody2D	

export var SpeedUp = 20
const MaxSpeed = 1000

func _ready():
	set_physics_process(true)
	pass
	
func _physics_process(delta):
	var bodies = get_colliding_bodies()
	for body in bodies:
		if body.is_in_group("Brick"):
			get_node("/root/World").score+= 1
			body.queue_free()
		if body.is_in_group("Brick2"):
			get_node("/root/World").score+= 5
			body.queue_free()
			
		if body.get_name() == "Paddle":
			var speed = get_linear_velocity().length()
			var direction = get_position() - body.get_node("Anchor").get_global_position()
			var velocity = direction.normalized()*min(speed+SpeedUp, MaxSpeed)
			set_linear_velocity(velocity)
			print(str(speed+SpeedUp))
	if get_position().y > 360:
		get_node("/root/World").balls+= 1
		queue_free()
	pass

so, what I’m doing wrong? every time the Ball node falls from Y>360 the score goes back to 1

:bust_in_silhouette: Reply From: hilfazer
var score = 0 setget set_score
var balls = 0 setget set_score

Both variables are using the same setter set_score. Use the other function for balls.

bolas = value

balls = value ?

oh, I think I got it!
I learned that set_ in set_score was a setter on itself, not that was set_ and then a variable/ref
“bolas” and “balls” are the same thing, i just coded on PT-BR and transalted to english as I pasted the code.
Thanks for the help @hllfazer! Got fixed.

Gisore | 2019-10-05 16:07