The error occurs when i want to call a function that seems to be nil...
This is the code:(UNDERLINED IS WHERE ERROR OCCURS)
local select = 1
local running = true
local function clear()
term.clear()
term.setCursorPos(1,1)
end
local function printMenu(menustate)
clear()
for i = 1, #menustate do
if i == select then
print(">"..menustate[i].opt)
else
print(menustate[i].opt)
end
end
end
local function control()
changeState("control")
end
local function keyHandler(menustate)
event, key = os.pullEvent()
if key == 200 and select > 1 then
select = select - 1
elseif key == 208 and select < #menustate then
select = select + 1
elseif key == 28 then
menustate[i].action()
end
end
local menu = {
["main"] = {
[1] = {opt = "Control", action = control},
[2] = {opt = "Command", action = command},
[3] = {opt = "Exit", action = exit}
},
["control"] = {
[1] = {opt = "Lights", action = light},
[2] = {opt = "Door", action = door}
},
["command"] = {},
["lights"] = {}
}
local menustate = menu["main"]
local function changeState(newstate)
menustate = menu[newstate]
end
while true do
printMenu(menustate)
keyHandler(menustate)
end
Edited by aceyo369, 17 August 2014 - 05:05 PM.












