|
I am using C# and I have a situation in which I need to wait for a coroutine to finish. However, the call for StartCoroutine is being done inside a bool function, so the yield keyword is not available to me. Essentially, the bool function is being returned before the coroutine can finish and set the return bool properly. Is there a way to wait for the coroutine without the yield keyword? Here is the code:
(comments are locked)
|
|
Basically, what you are trying to do here fundamentally doesn't make sense. It sounds like it should work, but when you think about it, you're basically asking the entire program to halt, waiting for this one value to return. There's a reason why Coroutines work the way they do- they have to be able to act separately from the rest of the program. Instead of using a method that returns a straight bool, split it into two methods- Then, in your other script, call the StartScoreCheck when you want to send a request, and then poll PollGuestScores() every frame until the result returns successfully. Possibly, you could have PollGuestScores return a datatype which includes an 'undefined' state, for before the result has returned- Then make bPostScore not a boolean, but a ScoreInfo (and I guess change its name since it'd no longer be accurate), and set its state when the CheckGuestScores coroutine finishes. Thanks syclamoth. I was trying to avoid having to setup multiple function calls and a state system, but it appears it can not be avoided to achieve what I am looking for.
Nov 17 '11 at 06:46 PM
ENDERthegamer
(comments are locked)
|
