Qwertytops ok, I found something that might help:
https://stackoverflow.com/questions/77749279/godot-4-tosignal-string-parameter-in-c-sharp-for-await
https://docs.godotengine.org/en/stable/tutorials/scripting/gdscript/gdscript_basics.html#awaiting-for-signals-or-coroutines
Qwertytops I updated the question with an example which I hope clarifies it.
Qwertytops ```
async void MyFunction() {
// do something
// hang until a unit is selected
Unit unitSelected = await ToSignal(Events.events, "UnitClicked"); // UnitClicked carries the Unit that was clicked
// do something with unitSelected
}
the way await
works in gdscript, it pauses execution of the code until it receives a signal, the signal then resumes the code.
what you are trying to do is run a function and wait for a return value.
Maybe your approach to this problem is wrong. I would store the "return value" in a reference or in a singleton, and emit the signal when the unit has been selected, resuming execution, then I would use the value stored in the singleton or reference.
so I would have a singleton with a reference unitSelected
.
then, when a unit is selected it would override unitSelected
with self
and emit the signal unit_clicked
(also in the singleton):
mysingleton.unitSelected = self
mysingleton.unit_clicked.emit()
your paused code would then receive the signal and resume execution:
func myfunction:
await mysingleton.unit_clicked
#mysingleton.unitSelected