I wish people could share their experience managing coroutines in gdscript. I came from a background which I don’t have to deal with coroutines much. In gdscript, right now I have no way of telling if a function is a coroutine unless I take a look at the implementation or if I’m taking it’s output. Not awaiting for coroutines(because I don’t know they are) has caused a ton of bugs for me. My current approach is to comment all my coroutines but I was hoping for something like a tag which is much easier. Even better is if editor’s autocomplete can tell me that a function is a coroutine. How do you guys deal with this?
In GDScript any function can become a coroutine by just adding “await” keyword somewhere in the body of the function, so I don’t see a reason for drawing a solid line between the two and honestly never had any issues with distinguishinging and using it either. And that’s without any specific labeling of coroutines.
Also, you don’t always want to await for a coroutine, so each case should be treated separately anyway.
If you don’t mind sharing some examples that caused you troubles in the past, maybe we can suggest some improvements.
here tween_val_using_different_trans is a coroutine but I accidentally forgot to await for it and it caused the label to not display what I want. In the long run, I find this difficult to maintain when you can’t tell if a function is a coroutine or not by simply looking at it. A month later when I come back to this piece of code I’ll have to click through all their implementations to see if I need to await them or not.
I think you’re looking at it wrong. It’s not about that you “must” await a coroutine, but do you “need” to await it.
It’s the same as with the return value of a function. You can have a function returning a value, but do you need to use it elsewhere in the code is another thing, because you can discard the return value. And same as with a coroutine - there usually no good indicator that a function returns a value, unless you specifically name a function in a way that can easily identify it.
In your example, and I know it’s a bit overexaggerated for the example purpose, just looking at the code it’s almost obvious there is something missing there, otherwise 2nd and 4th line will do the same thing twice.
Sorry I don’t have a good answer to you, but I honestly don’t see it as much of an issue as you do. Maybe simply labeling your coroutine functions more clearly with a “coroutine” keyword might be the solution for you.