lua-users home
lua-l archive

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


I've integrated Lua in to my game. I've started running scripts that call back in to my code and 'does stuff'. I've just started modifying my code so it can handle multiple scripts at the same time(the hard part was working out how a class can self register it's function binding against each new instance but I think I have that one licked too.

What I can't work out is how I can use Lua for something other that configuration scripts. For example right now I use Lua to configure the start-up state of my game, which GUI windows are active, do I play sounds etc. What happens when I want to use Lua to control the way my games missions are run?

Simple example: 

Capture The Flag. I would imagine that I need to check the collision state between flags and capture zones to determine if I award a score. I would call in to my game to do the collisions, perhaps passing in the entity ID so the game can match the flag to an object in the physics engine and hence do the collision against the second entity(the capture zone). Now I'd imagine that I'd write a script to sit there looping, waiting for the mission to complete, like 10 caps or perhaps a score threshold to be reached, On exit lua_dostring returns.

How does my code run in the mean time?

A) Is there a way to run my code until it hits some kind of Yield() where the state is stored and control passed back to my code so it can render frames. Then each frame I check to see if the script needs to do anything.
B) Must I run a separate thread so the script runs concurrently with the rendering of the game and lua_dostring will only return when the script hits the end? Currently I don't use threads for my game.
C) Must I design my scripts to be stateless and be able to be run from begin to end completely each frame(that would suck)

How do you generally make this work?

Many thanks,

Chris


NOTICE
This e-mail and any attachments are confidential and may contain copyright material of Macquarie Bank or third parties. If you are not the intended recipient of this email you should not read, print, re-transmit, store or act in reliance on this e-mail or any attachments, and should destroy all copies of them. Macquarie Bank does not guarantee the integrity of any emails or any attached files. The views or opinions expressed are the author's own and may not reflect the views or opinions of Macquarie Bank.