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 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 (54 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 (29,360 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 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.