Hi,
I am coding a Javascript finite state machine based on and adapted from the C# FSM framework found at the unity wiki. I am trying to add a delay so the animation ends before changing to another state but I obtain the next error:
Assets/Scripts/example.js(192,18 ) BCE0101: Return type ‘void’ cannot be used on a generator. Did you mean ‘IEnumerator’? You can also use ‘System.Collections.IEnumerable’ or ‘object’.
The script es called example and it has all the state class implementations (Idle, Run, Turnaround,…)
Any ideas?
Thanks
class Turnaround extends FSMState {
function Turnaround() {
stateId = StateId.turnaround;
}
function Reason(player : GameObject) {
yield player.GetComponent(example).StartCoroutine(player.GetComponent(example).wait(1));
player.GetComponent(example).SetTransition(Transition.turnaroundIdle);
}
function Action(player : GameObject) {
player.GetComponent(example).aniSprite(16, 6, 0, 5, 5, 16);
}
}
function wait(waitTime : float) {
yield WaitForSeconds(waitTime);
}
Hi Dave, thank you for the interest. I found the related post, but when I declare the return type IEnumerator in wait() and Reason() functions (also in the parent class function) the error disappears but coroutine is never executed!.
– ZaqnafeinI think it is being executing but you're expecting it to do something after the wait, which isn't specified in that wait method. Remember that starting a Coroutine is not a "blocking" function. After you start it, the code continues to execute at the next line. Right now, you wait for 1 second and then ... nothing else happens because nothing else is in the routine.
– Dracorat