- Home /
Ienumerator return string
I have a function called "GetResult" that i call and pass in a string, which calls an ienumerator using the variable passed in. The ienumerator uses the WWW api to retrieve a string. I am trying to get the "GetResult" function which returns a string to return the result on the ienumerator, which as i understand cannot return the string itself.
public string GetResult(string l){
StartCoroutine(GetData(l));
return result;
}
The "result" variable is a public variable which the ienumerator stores the result of the WWW request in. However as the function returns the string before the corutine has completed, i am unable to return the correct data.
How can i call the function "GetResult" and have it return the "result" variable, but after the corutine completes ?
I don't think there's a built-in way to wait for a coroutine to finish executing before executing more code.
You can set boolean flags like isResultValid
in the coroutine and check them in relevant parts of code that you want to use result
.
Your answer
Follow this Question
Related Questions
Yielding in between functions... 2 Answers
C# How to ping servers and get server latency? 1 Answer
How to return a variable outside NotificationCenter 0 Answers
Re-using the "same" for loop? 1 Answer
Coroutoutine doesnt work properly. 3 Answers