Posted 06 October 2012 - 12:55 PM
So basically this is my menu API
and this is the code im using to run it
anyway im getting some wierd errors like the args dont seem to be coming across can anyone debug it for me?
local function center(str, width)
local blank = string.rep(' ',math.floor((width-#str)/2))
return blank .. str
end
local function printc(stri,coordx,coordy)
term.setCursorPos(coordx,coordy)
write(stri)
end
local function split(str, pat)
local t = { }
local fpat = "(.-)"..pat
local last_end = 1
local s, e, cap = str:find(fpat, 1)
while s do
if s ~= 1 or cap ~= "" then
table.insert(t,cap)
end
last_end = e+1
s, e, cap = str:find(fpat, last_end)
end
if last_end <= #str then
cap = str:sub(last_end)
table.insert(t, cap)
end
return t
end
selected = 1
function create(title,items,blurb,func)
if selected == nil then selected = 1 end
term.clear()
term.setCursorPos(1,1)
printc("+----------------------------+",11,1)
printc("|"..center(title,28),11,2)
printc("|",40,2)
printc("+----------------------------+",11,3)
printc("| |",11,4)
printc("| |",11,5)
printc("| |",11,6)
printc("| |",11,7)
printc("| |",11,8)
printc("| |",11,9)
printc("| |",11,10)
printc("| |",11,11)
printc("| |",11,12)
printc("| |",11,13)
printc("| |",11,14)
printc("+----------------------------+",11,15)
printc("| |",11,16)
printc("| |",11,17)
printc("+----------------------------+",11,18)
for linen, item in ipairs(items) do
if linen <= 10 then
term.setCursorPos(14,3 + linen)
print(item)
end
end
term.setCursorPos(13,3 + selected)
print("["..items[selected].."]")
blurbword = split(blurb[selected]," ")
local l1 = ""
local l2 = ""
for i,w in ipairs(blurbword) do
if string.len(l1..w) <= 25 then
if i == 1 then
l1 = w
else
l1 = l1.." "..w
end
elseif string.len(l1..w) > 25 then
if string.len(l2..w) <= 25 then
if string.len(l2) == 0 then
l2 = w
else
l2 = l2.." "..w
end
end
end
end
printc(l1,13,16)
printc(l2,13,17)
end
--selected = 1
--create()
--term.setCursorBlink(false)
while true do
local sEvent, param = os.pullEvent()
if sEvent == "key" then
if param == 28 then
func[selected]()
elseif param == 208 then
if selected < #items then selected = selected + 1 end
create()
elseif param == 200 then
if selected > 1 then selected = selected - 1 end
create()
end
elseif sEvent == "terminate" then
break
end
end
and this is the code im using to run it
os.loadAPI("menu")
func = {function() print("hello");print("bob") end}
title = "Programs"
items = {
"Set Lobby Sign", --Menu item One
"Open End Door", --Menu item two
"*Blank*", --Menu item three
"*Blank*", --Menu item four
"*Blank*", --Menu item five
"*Blank*", --Menu item six
"*Blank*", --Menu item seven
"*Blank*", --Menu item eight
"Debug", --Menu item nine
"Exit" --Menu item ten
}
blurb = {
"Sets The Lobby's Monitors Text", --Menu item 1 blurb
"Opens the Secret Door In Lobby to End Portal", --Menu item 2 blurb
"*Blank*",--Menu item 3 blurb
"*Blank*",--Menu item 4 blurb
"*Blank*",--Menu item 5 blurb
"*Blank*",--Menu item 6 blurb
"*Blank*",--Menu item 7 blurb
"*Blank*",--Menu item 8 blurb
"Allows User To Edit Codes",--Menu item 9 blurb
"Logs Off The Computer"--Menu item 10 blurb
}
menu.create(title,items,blurb,func)
anyway im getting some wierd errors like the args dont seem to be coming across can anyone debug it for me?