- Home /
What is the meaning of Generators cannot return values?
I'm unlear of why a certain functions are not able to return a value. eg
var x:String;
x=ReturnSomething();
function ReturnSomething() { if(somethingDifferentHappened) { return("Something different"); } return("Something ordinary"); }
are these 'nested' returns the root of the problem?
Answer by Mike 3 · Dec 31, 2010 at 11:28 AM
Usually it'll be because your function has a yield in it, which turns the function into a generator.
The compiler turns those functions into a pretty blank function which creates and returns an instance of a class, which has the code from your original function inside it.
Because the function has to return that class, it can't return whatever you're trying to return yourself.
Gotcha..my above example probably actually works, but the one in my game does indeed have a yield in it. I can pretty much understand this because of course the var which calls the fuction would never actually recieve anything back until the functions yield had completed.
you can't solve the problem that you can't return a value from a coroutine.
indeed conceptually .......... you can't solve the problem "what the hell do I do while some other thingy is running ?"
just code around it .. typically with a callback
so have a new routine called something like ThatOtherDamnThingHasFinallyFinished
at the end of your quasi-thread you must call to that routine.
that's life !
Your answer

Follow this Question
Related Questions
How do I return a reference to an object downloaded via a function? 0 Answers
how do i generate cubes to form a sphere? 4 Answers
Random box generator in certain area. 1 Answer
Null reference for variables(prefabs) when referencing another script 0 Answers
Returning byte array from Java/Android 3 Answers