var waitfortimer = false
func _process(delta):
if Input.is_action_pressed("letter_B"):
$Timer.wait_time = 1 # wait_time in seconds
$Timer.start()
waitfortimer = true
if !waitfortimer: # checks if waitfortimer is false
# here comes the code that must wait for your wait_time
# more code
# much more code ;-)
# outside code will not have the time effect
func _on_Timer_timeout():
$Timer.stop()
waitfortimer = false
dont forgot to link the timeout signal of the timer to your script
I would like to program an AnimatedSprite who uses the bicycle when I pressed the ‘B’ key, so the code in _func(delta) is:
var bicycleActivated = false
func_(delta):
if Input.is_action_pressed("B"):
if bicycleActivate == false:
bicycleActivated = true
print("Bicycle activated")
else:
bicycleActivated = false
print("Bicycle disactivated")
if Input.is_action_pressed("ui_up"):
some codes that update the Sprite position...
elif Input.is_action_pressed("ui_down"):
some codes that update the Sprite position...
elif Input.is_action_pressed("ui_left"):
some codes that update the Sprite position...
elif Input.is_action_pressed("ui_right"):
some codes that update the Sprite position...
So with this code, when I press the 'B' button, the function is so fast that takes the input 'B' pressed multiple times and shows in output: Activated, Disactivated, activated for example.
I want to press the ‘B’ key and activate the bicycle, for this reason I asked how to stop for some seconds the _func(delta).
I update the code with your hints like this:
var bicycleActivated = false
var waitfortimer = false
func_(delta):
if Input.is_action_pressed("B"):
$Timer.wait_time = 1 # wait_time in seconds
$Timer.start()
waitfortimer = true
if !waitfortimer:
if bicycleActivated == false:
bicycleActivated = true
print("Bicycle activated")
else:
bicycleActivated = false
print("Bicycle disactivated")
if Input.is_action_pressed("ui_up"):
some codes that update the Sprite position...
elif Input.is_action_pressed("ui_down"):
some codes that update the Sprite position...
elif Input.is_action_pressed("ui_left"):
some codes that update the Sprite position...
elif Input.is_action_pressed("ui_right"):
some codes that update the Sprite position...
func _on_Timer_timeout():
$Timer.stop()
waitfortimer = false
When I play the Scene the Output is: bicycle activated, bicycle disactivated without an end, if I pressed B the output stops, but if I pressed another time B nothing is happen.