Topic was automatically imported from the old Question2Answer platform.
Asked By
ismaelgame7
Old Version
Published before Godot 3 was released.
Hello people, how are you?
I wanted to check if a button was pressed only once, But I do not know how to do this.
I was wondering if you have any way to do this.
In the game maker it is easier to do this.
You can add a script to that button. For example like this:
var buttonIsPressed = false
func _ready():
pass
func _on_YourButton_pressed():
if(buttonIsPressed == true):
#doNothing, because it's pressed before
else:
buttonIsPresed = true
doSomething()
So you have to make a variable where you can store data when the button is pressed.
You can also do with numbers.
var buttonIsPressed = 0
func _ready():
pass
func _on_YourButton_pressed():
if(buttonIsPressed >= 0):
#doNothing, because it's pressed before
else:
butonIsPressed = (1 + buttonIsPressed) #increasing the count with 1+
doSomething()
This way you set exactly how many times you can press the button.
I wanted to check one of my keyboard keys if I was pressed once.
Because I wanted to make a double jump to my project.
A friend has already helped me in this and here is an example for anyone who wants to use: