I encountered a strange behavior in an async function.
This is the function:
var success := false
if not effects().is_empty():
for effect in effects():
@warning_ignore("redundant_await")
var result := await effect.play(ctx)
print(success)
print(not success)
if result:
success = true
elif not success:
break
So it loops through effects, gets the result (which is a boolean) and then decides to set success or break.
The strange behavior is: the first print output is false which is correct, but the second print output is GDScriptFunctionState. If I for example put print(await not success) it returns the correct value true. The same applies for result. That causes the elif not to work, because GDScriptFunctionState is not true. But when I change the if result to if result == true it works and I also have no idea why. Also adding the line print(not success) also fixed it. I guess some timing issue or something.
Another thing, if i do this:
var res_v := await effect.play(ctx)
var result: bool = bool(res_v)
Is this normal behavior? In other parts of my code I also didn’t have to do this.
Does anyone know how this can happen or has any clues why it happens?
Hi, I created the most minimal Project I could create to reproduce this behavior: GitHub - mLampir/Godot-Bug: This is the minimal Project to reproduce a Bug(maybe?) in Godot.
It took me many hours ^^
It definitely has something to do with the abstract function that isn’t a coroutine and the inherited function which is. When I “declare” the function in the effect like this
I simplified the TargetingApi, but there is not much more I can remove. Effect, DamageEffect and TargetingApi are all 3 needed to reproduce, these are the key parts and they are now as simple as possible. Then there is only Main to control them, but there is also not much to remove. To reproduce the problem two interactions are needed one to start and one to cancel. I implemented it with a button. I could also start it with a timer in between or something without user interaction, but I don’t think thats necessarily better.
I tried, but I couldn’t reproduce it. It is this specific constellation that creates the behavior. This is the minimal version I could create. It took me about 5-10 hours to create this, so I will not put any more time in it. I think I will just raise a bug on GitHub with the information, after all the testing im pretty sure it is a bug.
Getting GDScriptFunctionState sure looks suspiciously bug-like, but I’m pretty sure the example could be reduced further. This would also increase the likelihood of it being fixed quicker, if it’s indeed an engine bug.