- Home /
How To Create Coroutine Delegates?
Lamely attempting to create an array of coroutines and get the following error: "Cannot convert 'function(): System.Collections.IEnumerator[]' to 'System.Collections.IEnumerator[]'."
I've tried a whole bunch of combinations of types for the variable "coroutine" but keep getting different kinds of errors. Here's my latest attempt:
var coroutines : IEnumerator[];
function Start()
{
coroutines = [First, Second, Third];
yield StartCoroutine(coroutines[0]);
yield StartCoroutine(coroutines[1]);
yield StartCoroutine(coroutines[2]);
print("Done!");
}
function First() : IEnumerator
{
print ("First!");
yield WaitForSeconds(2.0);
}
function Second() : IEnumerator
{
print ("Second!");
yield WaitForSeconds(2.0);
}
function Third() : IEnumerator
{
print ("Third!");
yield WaitForSeconds(2.0);
}
Any thoughts? Maybe what I'm attempting isn't possible in Javascript?
Answer by ArkaneX · Oct 01, 2013 at 01:33 PM
Please change this line
coroutines = [First, Second, Third];
to
coroutines = [First(), Second(), Third()];
Forehead slap - that worked. Don't want to think about how many hours I blew trying to crack this. Thank you very much!
Your answer
Follow this Question
Related Questions
Yield position within while loop in coroutine 1 Answer
Coroutines and states 1 Answer
JS Wait for a function to complete - no WaitForSeconds 1 Answer
StartCoroutine important for using yield? 1 Answer
Fire and forget coroutines 1 Answer