lua-users home
lua-l archive

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


> After playing with it to learn it how to use it, I discover it isn't 
> what I was looking for. I really needed a delay or sleep function.

As Luiz points out os.execute"sleep 20" will work (at least on *nix
systems), but on a game I worked on recently I used a different
approach. It was a commercial title so I cant post any code. The system
was quite simple though so a verbal description should do.

First, I have a C function that is called once per game update. That
function calls the update function of a Lua scheduler that I wrote
passing the delta time since the last update as a parameter. Lua scripts
can register update functions with the scheduler by passing in 3
parameters: the update function, an optional table that will be passed
as the first parameter to the update function (so Object style tables
work) and a time in milliseconds desired between updates (if this is 0
the function is called every update). This simple system gave me a lot
of power in when the game logic was updated. 

If the delays are less regular than in my game then perhaps using a
coroutine scheduler would be more effective. Coroutines could yield with
a time parameter. The scheduler would then resume them when the time has
elapsed. 

- Daniel