I developing a game engine, and want the game to process a lua file.
Currently I'm using a custom scripting language I wrote to store each command in a list the game can can execute. My scripting language is very primitive at this point, which is why I want to switch to Lua, but I'm not sure how to proceed.
Here is an example of what I'm trying to do:
engine.message("Text") // Pause until player clicks a button
engine.message("Text2") // Pause until player clicks a button
chosenValue = engine.choose("Option1|Option2") // Wait for player to choose, then assign value
if(chosenValue="Option1") then
engine.message("One") // Pause until player clicks a button
else
engine.message("Two") // Pause until player clicks a button
end
I solved it by running Lua on another thread, and using a
Semaphore
with 1 permit that is taken when the script starts. When I want to pause, I request a permit from the Lua thread which pauses the whole thing, and when the user clicked a button I release a permit