Posted 19 January 2013 - 06:18 AM
Im getting an error at line 52 and i suppose it goes for most of the variables i create in the table.
–[[ Local Variables ]]–
local termWidth, termHeight = term.getSize()
local inMainMenu = true
local inLightsMenu = false
–[ Menu Methods ]]–
function Choice1()
term.clear()
term.setCursorPos(1,1)
print("hello!")
sleep(2)
end
function Choice2()
inLightsMenu = true
selectedItem = 1
while inLightsMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(lightsMenu)
event, key = os.pullEvent("key")
mouseClick( key, lightsMenu )
end
end
function LightsOn()
print("lights online")
sleep(2)
inLightsMenu = false
end
function LightsOff()
print("lights offline")
sleep(2)
inLightsMenu = false
end
function Exit()
inMainMenu = false
end
–[[ Menu Definitions ]]–
mainMenu = {
[1] = {
text = "Choice 1",
buttonType = 1,
optionStartX = termWidth-math.floor(string.len(mainMenu[1].text))/2,
optionEndX = termWidth/2+math.floor(string.len(mainMenu[1].text/2)),
optionStartY = math.floor(termHeight/2)-1,
optionEndY = math.floor(termHeight/2)-1,
handler = Choice1
},
[2] = {
text = "Choice 2",
buttonType = 1,
optionStartX = termWidth/2-math.floor(string.len(mainMenu[2].text/2)),
optionEndX = termWidth/2+math.floor(string.len(mainMenu[2].text/2)),
optionStartY = math.floor(termHeight/2),
optionEndY = math.floor(termHeight/2),
handler = Choice2
},
[3] = {
text = "Exit",
buttonType = 1,
optionStartX = termWidth/2-math.floor(string.len(mainMenu[3].text/2)),
optionEndX = termWidth/2+math.floor(string.len(mainMenu[3].text/2)),
optionStartY = math.floor(termHeight/2+1),
optionEndY = math.floor(termHeight/2+1),
handler = Exit
}
}
lightsMenu = {
[1] = {text = "Lights On", handler = LightsOn },
[2] = {text = "Lights Off", handler = LightsOff }
}
–[[ Printing Methods ]]–
function printMenu( mainMenu )
term.clear()
term.setCursorPos(1,1)
for k,v in ipairs(mainMenu) do
term.setCursorPos(mainMenu[k].optionStartX, mainMenu[k].optionStartY)
print(mainMenu[k].text)
end
end
–[[ Handler Method ]]–
function mouseClick(mainMenu)
event, buttonType, x, y = os.pullEvent("mouse_click")
for k,v in ipairs(mainMenu) do
if buttonType == mainMenu[k].buttonType then
if x >= mainMenu[k].optionStartX and x <= mainMenu[k].optionEndX and y >= mainMenu[k].optionStartY and y <= mainMenu[k].optionEndY then
mainMenu[k].handler()
end
end
end
term.clear()
term.setCursorPos(1,1)
end
–[[function mouseClick()
curX, curY = term.getCursorPos()
event, button, X, Y = os.pullEvent("mouse_click")
XY = X..","..Y
if button == 1 then
if (X => and X <= 6 and Y =>1 and Y =< 6) then
onItemSelected(menu)
end
end
end]]–
function onItemSelected( mainMenu )
mainMenu[selectedItem].handler()
end
–[[ Main Method ]]–
function main()
while inMainMenu do
term.clear()
term.setCursorPos(1,1)
printMenu(mainMenu)
event, key = os.pullEvent("key")
mouseClick(key,mainMenu)
end
end
main()