+1 vote

Hello i am implementing my game touch screen buttons and i have a problem.

i need the button to be disabled for 2 seconds before it can be pressed again but i cannot seem to fix this issue.

i have tried setblocksignals(true) but it did not help.

this is my code. thankyou.

func _on_fire_button_pressed():
      set_block_signals(true)
      $Timer_1.start()                                                                                                                              func _on_Timer_1_timeout():
      set_block_signals(false)
in Engine by (25 points)

Maybe try setprocessinput()?

no i tried it did not work. any idea how i can achieve this?

2 Answers

0 votes

for future reference i fixed it this way :

func _on_fire_touch_pressed():
    $fire_touch.action = "nothing"                                                              
    $fire_touch.visible = false
    yield(get_tree().create_timer(2),"timeout")
    $fire_touch.visible = true
    $fire_touch.action = "fire"

in input_mapping make a nothing button which does nothing and use it in here. like shown above.

by (25 points)

Nice. This will come in handy

0 votes

Well, I guess you could have a bool "can_fire" which is set to false when the button is pressed and set to true when the timer expires. Use this bool to then determine whether the pressing of the fire button results in any action.

by (16 points)

yes i tried it too but it did not work for me i dont know why

How about this?

func _on_fire_button_pressed():
    if (can_fire):
        can_fire = false
        $Timer_1.start()
        print("Firing")
    else:
        print("Can't fire yet")

func _on_Timer_1_timeout():
    can_fire = true

Or even this to effectively disable the button (get the button mask in the ready function and set it back accordingly):

func _on_fire_button_pressed():
    if ($fire_button.button_mask != 0):
        $fire_button.button_mask = 0;
        $Timer_1.start()
        print("Firing")

func _on_Timer_1_timeout():
    $fire_button.button_mask = 1;

thanks a lot. i fixed my problem my way. maybe in future your solution will be useful for someone. thankyou.

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.