This is the testing Godot forums! All forum posts unique to this forum will be deleted! Please use the main forums here for any posts you want to keep. All forum rules still apply.

Is It possible to yield more than 1 button/texture button get pressed?

IzZI127IzZI127 Posts: 3Member

I am noob at Godot and i've decided to develop my skills while coding a boardgame.
Now i'm facing a problem with "yield".
I need the game to wait till one of several buttons gets pressed and i don't know how to do It. Can you guys help me with a solution?

Answers

  • IzZI127IzZI127 Posts: 3Member

    Hey guys, i'm new to godot and i've decided to learn while coding a boardgame. Right now i'm stuck 'cause i can't find a proper way to wait till a button gets pressed. The problem is, there are several buttons. What i'm trying to say is, i need the yield command to wait if one of several buttons is pressed. I've been looking for answers in many websites and in the documentation, but i'm struggling to find how to do it. Can you guys provide me a solution? Thank you.

  • TwistedTwiglegTwistedTwigleg Posts: 2,561Admin

    Welcome to the forums @IzZI127!

    You could use a signal and a boolean to stop code execution until a button is pressed. It wouldn't be using yield, but it should achieve the same effect. Something like this (untested):

    extends Control
    # Will be used to check if the buttons are pressed or not
    var is_buttons_pressed = false
    
    func _ready():
        # Get the button(s) and connect their pressed signal
        get_node("ButtonNodeHere").connect("pressed", self, "_on_button_pressed")
    
    func _process():
        # check if the buttons have been pressed
        if is_buttons_pressed == true:
            print ("Button was pressed!)
            # do whatever you need to do when a button is pressed here!
    
            # set is_buttons_pressed to false so the code only gets called once per button press.
            is_buttons_pressed = false
    
    func _on_button_pressed():
        is_buttons_pressed = true
    
  • IzZI127IzZI127 Posts: 3Member

    Thank you for the reception!
    I'll test today the suggested solution, and after that, i'll report what's happened.

Leave a Comment

Rich Text Editor. To edit a paragraph's style, hit tab to get to the paragraph menu. From there you will be able to pick one style. Nothing defaults to paragraph. An inline formatting menu will show up when you select text. Hit tab to get into that menu. Some elements, such as rich link embeds, images, loading indicators, and error messages may get inserted into the editor. You may navigate to these using the arrow keys inside of the editor and delete them with the delete or backspace key.