0 votes

Hi, I have a problem with the spawner counter on a project that i work.

var sprite=load("res://Scene/Sprite.tscn")
var counter = 0


func _on_Button_pressed():
    var spawn = sprite.instance()
    add_child(spawn)
    counter =+1
    $Label.text = str(counter)

To be short it only show 1 and it get stuck there regardless how much I press the button. Any ideea?

P.S. Thanks in advance and sorry for bad english

in Engine by (47 points)

1 Answer

0 votes

You made a typo:

counter =+1

This will set the value of counter to +1. It's apparently valid code, cuz after all, +1 is a positive number. The + just happens to be optional, unlike - for negative numbers.

You should replace it with:

counter += 1

Which will increment the value of counter by 1.
(It's a shorthand for counter = counter + 1).

by (28,740 points)

Thanks you very much, i thought that is different from c++/c# the main reason been that i work from the book learn gotod in 24 hours and i saw there an incrementation that was write like that. I feel akward now... thanks again!

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.
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 webmaster@godotengine.org with your username.