I've dug it up, it's not a brilliantly coded text adventure - it was my entry for the Text Adventure Competition Matt Rock used to run. You can see how LUA manages it.
You will need these 2 following plugins to make the code work:
Barnski's Free LUA Plugin
And
D3DFunc DLL - because this offers faster and better looking text.
I'll try to explain the code a little here, mainly becauae I didn't comment it too well.
Essentially I just used LUA to store a lot of values to affect the game code.
So if I want to create a 'room' in this text adventure, my LUA file would look like this:
script = { current = "scripts/prologue/5-jail2.lua"}
title = "Jail"
background = "parent"
music = "parent"
text = { positionx = 10, positiony = 10}
body = "“They do horrible things,” a man from the other cell screams, “they make you believe, it’s...it’s a horrible place – your best way out is to escape!” *‘S&$t!’ I say to myself. I’ve never encountered ‘The Preacher’, but I know him by reputation – I don’t particularly think his is one to consider about right now, however we need to escape before he comes.* What should I do?"
choice = { count = 4
, n1 = { line = "Throw a brick at the guard"
, command = "loadscript"
, script = "scripts/prologue/6-escape.lua"
}
, n2 = { line = "Talk to Prisoner", command = "loadscript", script = "scripts/prologue/6-prisoner.lua" }
, n3 = { line = "Talk to Krem", command = "loadscript", script = "scripts/prologue/6-krem.lua" }
, n4 = { line = "Use stick with lock" , command = "loadscript", script = "scripts/prologue/6-lock.lua" }
}
To break it down:
Script = { current }
This is to tell DBP the name of the script (this was me being lazy in DBP)
Title = "..."
The title displayed for the room.
Background = "..."
Music = "..."
The image/music name of the background/music used, if "parent" is written, then it will use the image from the last room.
Text = { positionx, positiony }
The position of the text in the frame
body = "..."
This is the body of text used for describing what\'s going on. It's basically the narrative part.
choice = { count, n1 = {line, command, script}, n2 = {line, command, script}...}
This is used for the 'options' the player has in the text adventure. The 'Count' is used for an array to decide how many options the player has. So if you write '4' you need n1, n2, n3 and n4 complete. Because it's LUA, you can get away with multiple lines for a single line of script making it easier to read. With each 'option' you have line text, the command (for example if it says 'save' it'll perform what action 'save' does in DBP. If you write "loadscript" you'll have to use the 'script' argument to put in the file name.
Now, DBP will parse whatever script is thrown at it. And that\'s easy. You have to do the LUA LOAD FILE "..." to load your chosen script. I have my code use a default script and then after that have the script loaded depend on what the scripts tell DBP.
All you have to do then is check what's in the LUA script and code conditions for whatever the script contains. So, I have a variable called 'body', it's used as a string. So I store that into DBP as:
Body$ = lua string$("body")
That will grab "body" from the lua script.
Where there's a command, I could create some game logic.
if lua string$("choice.n1.command") = "end" then end
You'll see wherever I use a curly brace "{}" it'll be treated kind of like an object in object orientated programming, hence the dots.
I'm sure there's more to LUA than that, but it's how I used it.
Also, project is here.
https://www.dropbox.com/sh/1m1z3kzvk2rrwgy/ygR-2RGUtm/Pulse%20Demo