Quote:

I don't understand how the animate_walk function is an endless loop since it has a wait(1) at the end? Usually if I leave out the wait(1) I get a message saying that it's an endless loop.

Do I need to add a return function after the wait(1)?




It's an endless loop because it never exits. It's just a "polite" endless loop, it only runs once per frame.

This is what I think you are doing:

Code:


function animate_walk()
{
while(1) ///< this never exits
{
... do stuff
wait(1); ///< this waits one frame, then it starts over
}
}

action my_cool_guy()
{
... stuff
while(1) ///< this also never exits
{
... do stuff
animate_walk(); ///< call a new animate_walk function
wait(1);
}
}



In the first frame:
1) my_cool_guy runs until it calls animate_walk().
2) animate_walk runs until it gets to the wait(1) when it returns control to the my_cool_guy action.
3) my_cool_guy continues running until it reaches its wait(1).

BUT (and this is key to understanding lite-c) wait(1) only stops the function it is in for one frame.

In the next frame:
1) The animate_walk function created in the first frame continues running its loop until it reaches its wait(1) again.
2) Then my_cool_guy runs until it calls animate_walk() again, which will create a second instance of that function (with its own loop).
3) The second animate_walk() runs until it reaches wait(1)...


This might not make sense right away so, if you want the short answer, remove the "while(1)...wait(1)" loop from animate_walk() if you are calling it once per frame.


Conitec's Free Resources:
User Magazine || Docs and Tutorials || WIKI