Posted 09 October 2012 - 05:24 AM
EDIT: I fixed up the code (edited my main comment with the new code) and the main menu works now. I can ever switch into the lights menu and turn the lights on and off, perfect. When I try to hit the "To Do" option though I get this message:
menuBoard.txt:106: attempt to call nil
Line 106 should just be calling a specific handler. Why does it work for the lights menu but not to print my To Do list to the attached monitor ?
--[[Local variables]]--
local termWidth, termHeight = term.getSize()
local selectedItem = 1
local inMainMenu = true
local inLightsMenu = false
local inToDo = false
local monitor = peripheral.wrap("back")
--[[Menu Methods]]--
function lights()
inLightsMenu = true
selectedItem = 1
while inLightsMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(lightsMenu)
event, key = os.pullEvent("key")
onKeyPressed(key, lightsMenu)
end
end
function lightsOn()
rs.setOutput("bottom", true)
inLightsMenu = false
selectedItem = 1
end
function lightsOff()
rs.setOutput("bottom", false)
inLightsMenu = false
selectedItem = 1
end
function toDO()
inToDo = true
while inToDo do
monitor.clear()
monitor.setCursorPos(1,1)
for i=1,4 do
monitor.print(toDoList[i])
end
end
end
function topSecret()
end
function exit()
inMainMenu = false
end
--[[Menu Definitions]]--
mainMenu = {
[1] = { text = "Lights", handler = lights},
[2] = { text = "To Do", handler = toDo},
[3] = { text = "Top Secret", handler = topSecret},
[4] = { text = "Exit", handler = exit}
}
lightsMenu = {
[1] = { text = "Lights On", handler = lightsOn },
[2] = { text = "Lights Off", handler = lightsOff }
}
toDoList = {
"[1] RailCraft Building",
"[2] Bother Jared",
"[3] Make Cookies",
"[4] Brainstorm Frame Ideas"
}
--[[Printing Methods]]--
function printMenu( menu )
for i=1,#menu do
if i == selectedItem then
print(">> "..menu[i].text)
else
print(" "..menu[i].text)
end
end
end
--[[Handling Methods]]--
function onKeyPressed( key, menu )
if key == 28 then
onItemSelected(menu)
elseif key == 200 then
if selectedItem > 1 then
selectedItem = selectedItem - 1
end
elseif key == 208 then
if selectedItem < #menu then
selectedItem = selectedItem + 1
end
end
end
function onItemSelected( menu )
menu[selectedItem].handler()
end
--[[Main Method]]--
function main()
while inMainMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(mainMenu)
event, key = os.pullEvent("key")
onKeyPressed(key,mainMenu)
end
end
main()