lua-users home
lua-l archive

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


Unfortunately this option works in the opposite direction to the way
that my game platform is built.  My game platform run cycle is driven
from the C++ end, not lua.  

I've opted for my second option, where I've built the AI functions as
state machines.  Basically the lua AI script is called whenever the
actor is idle.  (I've expanded on this a bit more in my blog at
http://buzzrick.emedia.net.nz/dasBlog/2005/11/19/Integrating+Lua+Scripte
d+AI+Into+Actors.aspx) 

I'm definitely keen to do some experimentation with coroutines and see
what I can come up with in the future.  

Thanks
Beric 
-----Original Message-----
From: Thomas Harning Jr. [mailto:harningt@gmail.com] 
Sent: Friday, 18 November 2005 5:11 p.m.
To: Lua list
Subject: Re: Help with Lua Threads/Coroutines/(or something)

A good idea to implement this would be to use a system sort of like
this:
  actorRunner = coroutine.wrap(actorFunction)
  -- arguments passed inside the actorFunction's yield call
  (yieldedargs ...) = actorRunner(args,....)
.....
  for actor in actors do
    returnVals = actor(arguments...)
  end

Inside the actorFunction, you would want to have some loop that
continually does work, then calls coroutine.yield(args...)
One of the arguments that would be useful to pass into the
actor(..args..) would be an argument to tell the actor to "die",
that is, return out of the function without yielding.

With this, you wouldn't need to setup a new lua state for each
actor, as the coroutine setup would handle state preservation.


As for having the scripts schedule movement or something like that,
I'm not positive as to solutions, but the above should help.
-- 
Thomas Harning Jr.