- Home /
Definition of Script.function() depends on Script.function()...
I'm wanting to create a loop like so:
function foo() {
yield WaitForSeconds(1);
...
foo();
}
But I get the error
BCE0070: Definition of 'Script.foo' depends on 'Script.foo' whose type could not be resolved because of a cycle. Explicitly declare the type of either one to break the cycle.
I had a look around for the error code and had a read of the yield pages on the docs but I can't make sense of it. How can I create a loop like the above?
Answer by tertle · Feb 18, 2011 at 12:14 AM
Just create it as an infinite loop
function foo() { while(true) {
yield WaitForSeconds(1);
...
}
}
Answer by Eric5h5 · Feb 18, 2011 at 12:46 AM
Generally you shouldn't use recursion unless you actually need it, but just to answer the specific question here, the type of a coroutine is IEnumerator. So you can use
function foo() : IEnumerator
to fix the error message, though using an infinite loop is better in this case.
Answer by alexniver · May 10, 2014 at 05:52 PM
acturally, I have found a solution
http://forum.unity3d.com/threads/6906-recursive-calling
here, we can write javascript like this~
function ToJSON(obj : Boo.Lang.Hash) : String {
what unity need just a return Type
Your answer
Follow this Question
Related Questions
A delay/yield/wait function for function Update? 6 Answers
Yield Not Working - While Loop 3 Answers
Loop animation with a wait in between 3 Answers
Simple rotation script. (loop) 3 Answers
Error: type could not be resolved because of a cycle. 1 Answer