Posted 10 January 2013 - 02:46 AM
Im getting and error with my code,
menu:5: attempt to get length of function
I dont know what I'm doing wrong, can someone please help me.
menu:5: attempt to get length of function
I dont know what I'm doing wrong, can someone please help me.
local w, h = term.getSize()
local select = 1
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
local function printKlintos(str, ypos)
print(" ____ _______ ___ ____ ___ ___________ _________ __________")
print("| |// // | | | \\| | | _ | //")
print("| //| |__| | |___ ___| | | | ____//")
print("| \\| | | | | | | |_| |____ //")
print("|___|\\___\\______|___|___|\\____| |___| |_________|______//")
end
function drawMain()
printCentered("UP", 8)
printCentered("DOWN", 12)
printCentered("Quit", h-2)
local ypos = 9
if select == 2 then ypos = 13
elseif select == 3 then ypos = h-1 end
printCentered("---------", ypos)
end
function drawPicOne()
local upList = {
" /|\ ",
" / | \ ",
" / | \ ",
" | ",
" | ",
" | ",
" | "
}
for i=1,#upList do
printCentered(upList[i], 3 + i)
end
printCentered("DOWN", h-4)
printCentered("Back", h-1)
local ypos = h-3;
if select == 2 then ypos = h end
printCentered("---------", ypos)
end
function drawPicTwo()
local downList = {
" | ",
" | ",
" | ",
" | ",
" \ | / ",
" \ | / ",
" \|/ "
}
for i=1,#downList do
printCentered(downList[i], 2 + i)
end
printCentered("UP", h-4)
printCentered("Back", h-1)
local ypos = h-3;
if select == 2 then ypos = h end
printCentered("---------", ypos)
end
function drawHeader()
printCentered((printKlintos), 1)
printCentered(string.rep("-", w), 6)
printRight("by Klintos8", h)
end
local menustate = "main"
local mopt = {
["main"] = {
options = {"pic1", "pic2", "quit"},
draw = drawMain
},
["pic1"] = {
options = {"pic2", "main"},
draw = drawPicOne
},
["pic2"] = {
options = {"pic1", "main"},
draw = drawPicTwo
}
}
function runMenu()
while true do
term.clear()
drawHeader()
mopt[menustate].draw()
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] == "quit" then break end
menustate = mopt[menustate].options[select]
end
end
end
runMenu()
term.clear()
term.setCursorPos(1,1)