Posted 04 October 2012 - 01:11 AM
EDIT: I have partially abandoned this, as I have found a new menu script that works, but it doesn't look as nice, so I would still like help on this one. Thank you.
This is the code for a menu that I have drawn up. It is the startup file for my main control terminal, and I have had no problems, until now. To begin with, I only had the lockdown program linked to it, but when I added the opengate program, it broke. It still works when I select the lockdown function, but when I use the opengate option, it has this error: startup:50: attempt to index ? (a nil value)
This is my startup program
I cannot for the life of me figure out why it should be giving me an error, as it is working for one program, but not the other. I know it's not the opengate program itself, because I debugged and ran it by itself, and it worked. Any help will be greatly appreciated. Thank you in advance.
This is the code for a menu that I have drawn up. It is the startup file for my main control terminal, and I have had no problems, until now. To begin with, I only had the lockdown program linked to it, but when I added the opengate program, it broke. It still works when I select the lockdown function, but when I use the opengate option, it has this error: startup:50: attempt to index ? (a nil value)
This is my startup program
local w,h = term.getSize()
local select = 1
--[[Menu Functions]]--
local function printCentered(str, ypos)
term.setCursorPos(w/2 - #str/2, ypos)
term.write(str)
end
local function printRight(str, ypos)
term.setCursorPos(w - #str, ypos)
term.write(str)
end
function drawMain()
printCentered("Open the gate", 8)
printCentered("Lockdown", 12)
printCentered("Quit", h-2)
local ypos = 9
if select == 2 then ypos = 13
elseif select == 3 then ypos = h-1 end
printCentered("-x-x-x-x-x-x-x-x-", ypos)
end
function drawHeader()
printCentered("HEAD CONTROL", 1)
printCentered(string.rep("-x-", w), 2)
end
--[[Menu functions end]]--
local menustate = "main"
local mopt = {
["main"] = {
options = {"open", "lock", "quit"},
draw = drawMain
}
}
--Run function
function runMenu()
while true do
term.clear()
drawHeader()
mopt[menustate].draw() --This is line 50. This shouldnt be giving me an error isolated to just the opengate program--
local id, key = os.pullEvent("key")
--UP = 200, DOWN = 208, ENTER = 28
if key == 200 and select > 1 then select = select-1
elseif key == 208 and select < #mopt[menustate].options then select = select+1
elseif key == 28 then
if mopt[menustate].options[select] == "open" then
shell.run("opengate")
elseif mopt[menustate].options[select] == "lock" then
shell.run("lockdown")
elseif mopt[menustate].options[select] == "quit" then
os.shutdown()
end
menustate = mopt[menustate].options[select]
end
end
end
--run function end
rednet.open("left")
runMenu()
I cannot for the life of me figure out why it should be giving me an error, as it is working for one program, but not the other. I know it's not the opengate program itself, because I debugged and ran it by itself, and it worked. Any help will be greatly appreciated. Thank you in advance.