lua-users home
lua-l archive

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


ted wrote:
I would like to be able to write a script for my game to stage manage the
characters. Something like:

ogre = monster("Eric")

ogre:WalkTo(30, 40)

ogre:Say("HelloWorld")

The trouble is, with something like this the rest of my game will pause
until Eric's said his line. Is there a way each agent can call a script like
this, which will do a frame's worth of logic and then hand back control so
that everything else in the game can be updated too?

You probably want to look into Lua5's (possible-underdocumented)
coroutines.

With these you can manually yield a thread of control at
particular points (say within your Ogre logic) and resume
at a later time (say, the next frame).  Coroutines are useful
for 'hand-scheduling' stuff as well as funky things like
marvellous iterators and the ever-popular state machines
(along the lines of your requirements).

--Adam
--
Adam D. Moss   . ,,^^   adam@gimp.org   http://www.foxbox.org/   co:3
'Fox News and all the other right-wing pundits thrive by assuring
their audiences that they are the real unfortunates, oppressed by
problems as varied as big government, liberal media, taxes and the
bottom-feeders they serve, car-pool lanes, and France.'