[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Help with Lua Threads/Coroutines/(or something)
- From: "Beric Holt" <beric@...>
- Date: Fri, 18 Nov 2005 15:16:48 +1300
I'm trying to figure out the best way to implement the actor AI in my
game engine. I currently use Lua to perform lots of scripted tasks in
the engine, and now I'm starting to develop actors. I can't quite get
my head around how I should best implement the actor AI.
What I would like to be able to do is something like a lua thread or
coroutine (that is my best guess anyway). Each actor has a behaviour
script in lua. At the moment I can only script one action, such as
MoveTo(x,y). This move action takes some time to perform (many render
frames) so I'd like to suspend (yield?) the lua script and carry on
performing other important tasks in the C++ side (y'know, like rendering
to the screen and updating other actors and stuff). Once that actor's
task has been completed I could then resume the actor's script.
What is the best way of doing this. Do I need a separate lua state for
each actor? I've read the documentation on threads and coroutines, but
as I've never used these before I'm really struggling to apply them to
The alternate to all of this is to have the actor trigger his script
whenever it is idle (ie: finished doing the last action). The script
would then figure out what to do next, trigger the action, then exit.
Repeat when the action has completed, etc. I can see how to engineer
something like this, but it's not nearly as elegant as I'd like.