Await timer or signal

Godot Version



For a debugging purposes, I put await signal to see the label message in turn-based combat. My function takes both moves (player’s and cpu’s), so to see dmg/effects I need to put await between damage functions (no animations yet). I wanna put 2 sec delay or signal “mouse_clicked”, however they don’t work together.
await (get_tree().create_timer(2).timeout or mouse_clicked) # nothing works
await get_tree().create_timer(4).timeout or mouse_clicked # timeout works

To be honest I’m surprised the parser allows that syntax. you are using a logical or where await is is requires a signal variable. I don’t think it’s possible to await multiple signals simultaneously.

When you wrap in parentheses you are forcing the logical or to make a true/false expression evaluation. I’m surprised that await allows this syntax.

Without the parentheses I assume the await takes the first signal it finds and ignores the or and beyond. Or it somehow becomes part of the expression? Idk

There is a proposal for this syntax.

My suggestion would be to create an aggregate emitting signal function that will emit a new signal whenever the other two signals happen. And you should start a timer connected to that new function.

signal timer_or_mouse_click

Func _on_mouse_clicked():

Func need_to_await():
  Get_tree().timer(4). timeout.connect(func(): timer_or_mouse_clicked.emit())
 Await timer_or_mouse_clicked

Don’t forget that need_to_await() must be implemented in the script above the await for signal. It works only that way.

Gdscript hoists all property and functions within a class. It doesn’t care about decoration ordering unless it’s part of a function block.

It should also give you a nasty error if you forget to await a function that uses await.

Or am I misunderstanding your concern?

Class in turn-based combat? I call the function when the turn is over. Here’s the code:

func _on_text_gui_input(event):
	if (event is InputEventMouseButton && event.pressed && event.button_index == 1):

func await_click():
	get_tree().create_timer(2.0).timeout.connect(func(): text_clicked.emit())

(part of turn_logic function)
if first_move.Move_name != "Sleep Talk" and second_move.Move_name != "Sleep Talk":
			if exec_status(first_poke) != false:
				if second_poke.stats.invincible == true:
					hit_chance1 = 2
				first_poke.stats.invincible = false
				stab = stab1 if first_poke == active_poke else stab2
				$Text.text = str(exec_move(first_move, first_poke, second_poke, hit_chance1, effect_chance1, stab))
				print("First poke: ", first_poke.base_stats.poke_name)
				await text_clicked
			if second_poke.stats.hp > 0:
				if exec_status(second_poke) != false:
					if first_poke.stats.invincible == true:
						hit_chance2 = 2
					second_poke.stats.invincible = false
					stab = stab1 if second_poke == active_poke else stab2
					$Text.text = str(exec_move(second_move, second_poke, first_poke, hit_chance2, effect_chance2, stab))
			await text_clicked 
1 Like

Oh! okay I see what you mean

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.