#How to make "await" wait?

16 messages · Page 1 of 1 (latest)

proud badger
#

Hey, I'm having some trouble with await It's not awaiting.

signal progress_text_signal

func _on_continue_pressed():
emit_signal("progress_text_signal")
pass # Replace with function body.

func _set_info_text(text):
$"Player Screen/PanelContainer/Combat Options/Info Box/VBoxContainer/ScrollContainer/Info Text".text = text

await progress_text_signal

The signal is linked up to a continue button, but it's just going ahead without waiting for the button to be pressed. :/

proud badger
#

Did some additional testing.

    
    
    $"Player Screen/PanelContainer/Combat Options/Info Box/VBoxContainer/ScrollContainer/Info Text".text = text
    
    await progress_text_signal
    await get_tree().create_timer(5).timeout
    print("_set_info_text function called.")```

It doesn't print the debug message. It runs the `$` line, and then ends. I don't understand why it won't progress. But if I calls this function and THEN call await, it will wait. But not if it's inside the function.
#

Can anyone tell me what's going on here?

wind plinth
#

im not sure exactly what you're asking

#
extends Control

signal pressed

func _ready() -> void:
    $Button.pressed.connect(_on_button_pressed)
    _set_info_text("example text")

func _set_info_text(text: String) -> void:
    $Label.text = text
    await pressed
    print("button pressed")
    await get_tree().create_timer(3).timeout
    print("timer completed")

func _on_button_pressed() -> void:
    pressed.emit()

this looks pretty close to what you're doing and it works for me
text gets set during _ready(), pressing the button prints "button pressed", and then prints "timer completed" 3 seconds later

#

i dont think i understand what it is you're trying to do with this though

unkempt arch
#

also if you call the $"Player Screen/PanelContainer/Combat Options/Info Box/VBoxContainer/ScrollContainer/Info Text".text = text
before you call the await, then it will set the text before actually waiting for the signal

#

and will only print the "function called" after the signal is received

proud badger
#

Let me clarify.

I want the text to change, and then wait until the player presses a button to continue.
the await get_tree().create_timer(5).timeout was just there to test if it would wait at all, which it was not.

Right now it changes the text and then immedietly progresses. It does not go to the await functions, or the debug. It does not complete the function, and I don't understand why.

wispy sigil
#

I think what you want is this?

await Signal(pressed)

wind plinth
#

could you share more of your code so i can get a better idea of what you're doing with this?

unkempt arch
#

again, you can do this without await by just connecting it to the get_button_up or get_button_down signal, and i guess having the first instance of what i assume is a dialogue box be run either manually or by connecting it to another signal (so having two signals connected)

proud badger
#

I don't think that's going to work.

This is a turn based RPG.

I need to display text to the player telling them what happened, like if an attack hit or not, pause so the player can read the text, press a button or click (in this case just press a continue button) to progress to the next action in the tun order.

Click the attack button -> display text "you attack" -> press continue -> game checks to see if you hit (with RNG, no hit boxes are used) and you hit -> display text "you hit" -> press continue -> deals damage and checks if enemy is dead -> enemy is dead -> display text "enemy killed

It needs to wait until the player confirms that they have read the message. Await is supposed to pause the current function until another function has completed.

So, I call the text changing function in the middle of another function, and it should pause until the text change function is compelte.

And I put an await signal line in the text change function, so it wouldn't complete until the player clicks the button to progres.. Then it completes, and then the first function can continue.

That is the intention. So why does putting an await signal at the end of the function not work when I don't want it to progress until the player confirms to progress?

And I do not understand how connecting it to a button would help in any way. It's already waiting for a singal from a button.

proud badger
#

never mind. there was bit of script tacked on somewhere unexpected that was causing things to progress automatically. await is working fine. I just need to move around some code.

thank you for your help.