0 Members and 3 Guests are viewing this topic.
Text "Choose your own adventure!"Text "You wake up."sq("Get out of bed?")If qa = 1 Then Text "You get out of bed." sq("Eat some breakfast?") If qa = 1 Then Text "You eat some delicious breakfast." Text "You win! You ate delicious breakfast." Else Text "You go without breakfast." Text "You should always start your day with breakfast!" Text "You lose!" EndifElse Text "You stay in bed all day." Text "You lose. You shouldn't be so lazy."Endif
local jumpTable = { [1] = {"Choose your own adventure!"}, [2] = {"You wake up."}, [3] = {"Get out of bed?", {y=4, n=11}}, [4] = {"You get out of bed"}, [5] = {"Eat some breakfast?", {y=6, n=8}}, [6] = {"You eat some delicious breakfast."}, [7] = {"You win! You ate delicious breakfast.", "END"}, [8] = {"You go without breakfast."}, [9] = {"You should always start your day with breakfast!"}, [10] = {"You lose!", "END"}, [11] = {"You stay in bed all day."}, [12] = {"You lose. You shouldn't be so lazy", "END"} }local position = 1local question = falselocal input = ""local lines = {}function printLine(str) table.insert(lines, str)endfunction drawLines(gc) local height = platform.window:height() local lineHeight = 14 local linesMax = math.floor(height / lineHeight) - 1 local linesTotal = #lines local startLine = math.max(linesTotal - linesMax, 0) local line = startLine for y=1, math.min(linesMax, linesTotal) do line = line + 1 gc:drawString(lines[line] or "", 2, y * lineHeight - lineHeight, "top") endendfunction jump() local text local data local line while not data do line = jumpTable[position] text = line[1] data = line[2] printLine(text) position = position + 1 end if type(data) == "table" then position = position - 1 question = true printLine(">") end platform.window:invalidate()endfunction on.charIn(ch) if question then input = input .. ch:lower() lines[#lines] = ">" .. input platform.window:invalidate() endendfunction on.enterKey() if question then if input == "y" or input == "yes" then position = jumpTable[position][2].y else position = jumpTable[position][2].n end input = "" question = false jump() endendfunction on.paint(gc) drawLines(gc)endfunction on.construction() jump()end
[5] = {"Going to next table...","jumpTableExample2"}
I think I'd probably extend it into multiple tables for the purposes of my program, since there are several hundred 'lines'. I guess I would have a variable denoting which table I'm currently in, and have some sort of syntax in a line, say:Code: [Select][5] = {"Going to next table...","jumpTableExample2"}And then modify the table parser to recognise that line[2] is a string, and then jump to that table.