lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

On 09/01/2013 17.52, pass86 wrote:
I have 3 potential solutions so far:

1) wait(“<some condition>”);
The wait function takes a string, and evaluates it as a chunk until it returns true

2) repeat yield() until <some condition>;

3) yield( function return <some condition> end);
yield will return a function, the engine will store it in the registry and keep calling it until it returns true

If I remember correctly (it was some time ago) I started Lua game event handlers as coroutines, passing each of them a unique ID and storing them in an ID-indexed table. When a handler needed to wait for something (e.g. for the end of an animation) the scripting API function (e.g. Walk(character, toPlace)) notified the (C++) engine to start the requested action, then yielded. At the appropriate time (e.g. animation ended), the engine resumed the handler using the same ID to identify the coroutine to be resumed.