0 votes

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

in Engine by (15 points)

1 Answer

+2 votes
Best answer
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 ?

by (2,294 points)
selected by

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.

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.