Posted 23 October 2012 - 07:38 PM
[SOLVED]
I've written some functions for myself which i will put in a api for myself later but im having trouble getting it to work. I've managed to get the functions to return button im pressing but i cant seem to get it to run any code thats specified in the buttons table and im not sure how to implement it any ideas?
I've written some functions for myself which i will put in a api for myself later but im having trouble getting it to work. I've managed to get the functions to return button im pressing but i cant seem to get it to run any code thats specified in the buttons table and im not sure how to implement it any ideas?
w,h = term.getSize()
buttons = {}
function printC(ypos,str)
term.setCursorPos(w/2-#str/2,ypos) term.write(str) end
function printPos(xpos,ypos,str)
term.setCursorPos(xpos,ypos) term.write(str) end
function click(typ,x,y)
count = 1
for i,v in pairs(buttons) do
if buttons[i].coor[1] == x and buttons[i].coor[2] == y then
print(buttons[i].coor[3])
end
end
end
function hello()
print("hello")
end
function update()
term.setBackgroundColour(colours.blue)
shell.run("clear")
term.setBackgroundColour(colours.lime)
for i=1,h,1 do
if i==1 or i==h or i==4 then printPos(1,i,string.rep(" ",w))
elseif i<h then printPos(1,i," ") printPos(w,i," ")
end
end
term.setBackgroundColour(colours.black)
printC(2,"Picture Pass") printC(3,"Passcoded Lock Screen") term.setTextColour(colours.green)
end
function drawButton(xpos,ypos,colour,str,exe)
term.setBackgroundColour(colour)
printPos(xpos,ypos,str) printPos(xpos+#str,ypos," [X]")
buttons = buttons, {
[str] = {
coor = {xpos,ypos,exe}
}
}
buttons[str] = {coor = {xpos+#str+2, ypos}}
end
function mInput()
p1,p2,p3,p4 = os.pullEvent()
if p1 == "mouse_click" then click(p2,p3,p4) end
if p1 == "key" then press(p2,p3,p4) end
end
update()
drawButton(7,7,2,"Button","hello()")
drawButton(7,8,2,"other","hello()")
mInput()