0 votes

if the Button is pressed the first time then it wont count = 0 but the second time it will count +=1, how do I put this in code?

Godot version 3.2
in Engine by (17 points)

1 Answer

0 votes
Best answer

You can do it as follow:-

var count = 0
var first_time_pressed = false

func _on_Button_pressed():
    if first_time_pressed == false:
        first_time_pressed = true
        return
    count += 1

When the button is pressed for the first time it will make the first_time_pressed variable true and will break out of the function. When you click the button again it will add 1 to the count variable

by (884 points)
selected by
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.