lua-users home
lua-l archive

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


Thanks for the link Tom. Threads and coroutines worked out fine. What I do is start the script function in a thread in the host program. All the commands are c++ functions. Any that need to pause the script yield. When the command is finished, the host program calls resume. Simple and transparent once its set up. Works great.

Jack


Thomas Wrensch wrote:

I'm using Lua for game scripting. I'd like to have the script call a
command, pause execution until it is finished, then resume at the next
statement.

For example for an NPC:
PickupWeapon()
EquipWeapon()
MoveTo(40,40)
GuardLocation()

Obviously I don't want it equipping a weapon before it has picked it up.
From studying the documentation I think coroutines and threads are what
I should be looking into, but I wanted to ask before I head done a
possibly wrong approach.

There's been a lot of discussion on-and-off on this subject, and there are
several approaches using coroutines that work fairly well. One that I
played with a little bit was a simple scheduler written in Lua that can do
some of this. Check:

 http://lua-users.org/wiki/SituationScheduler

Having said that I should warn you that I am NOT a game developer. I wrote
this as a way of scripting simulations. I *think* it will work well for
games.

  - Tom