Posted 05 April 2014 - 09:22 PM
I made a simple program from direwolf20's button api.. Its very similar to his and I don't see why its not working :/.. Every time I try to run it, it says For input string: "1stfloorlights".. Its something I was doing messing around with one of my friends.. Heres the code.. Please help
local mon = peripheral.wrap("back")
mon.setTextScale(1)
mon.setTextColor(colors.white)
local button={}
mon.setBackgroundColor(colors.black)
function setTable(name, func, xmin, xmax, ymin, ymax)
button[name] = {}
button[name]["func"] = func
button[name]["active"] = false
button[name]["xmin"] = xmin
button[name]["ymin"] = ymin
button[name]["xmax"] = xmax
button[name]["ymax"] = ymax
end
function 1stfloorlights()
print("1st Floor Lights")
rs.setOutput("right",true)
end
function 2ndFloorLights
print("2nd FloorLights")
rs.setOutput("left",true)
end
function 2ndLightsOff()
print("2nd Floor Lights Off")
rs.setOutput("left",false)
end
function 1stLightsOff()
print("1st Floor Lights Off")
rs.setOutput("right",false)
end
function fillTable()
setTable("1st Floor Lights", 1stfloorlights, 1, 9, 2, 4)
setTable("2nd Floor Lights", 2ndFloorLights, 11, 19, 6, 8)
setTable("1st Floor Lights Off", 1stLightsOff, 20, 22, 9, 10)
setTable("2nd Floor Lights Off",2ndLightsOff, 23, 25, 11, 12)
end
function fill(text, color, bData)
mon.setBackgroundColor(color)
local yspot = math.floor((bData["ymin"] + bData["ymax"]) /2)
local xspot = math.floor((bData["xmax"] - bData["xmin"] - string.len(text)) /2) +1
for j = bData["ymin"], bData["ymax"] do
mon.setCursorPos(bData["xmin"], j)
if j == yspot then
for k = 0, bData["xmax"] - bData["xmin"] - string.len(text) +1 do
if k == xspot then
mon.write(text)
else
mon.write(" ")
end
end
else
for i = bData["xmin"], bData["xmax"] do
mon.write(" ")
end
end
end
mon.setBackgroundColor(colors.black)
end
function screen()
local currColor
for name,data in pairs(button) do
local on = data["active"]
if on == true then currColor = colors.lime else currColor = colors.red end
fill(name, currColor, data)
end
end
function checkxy(x, y)
for name, data in pairs(button) do
if y>=data["ymin"] and y <= data["ymax"] then
if x>=data["xmin"] and x<= data["xmax"] then
data["func"]()
data["active"] = not data["active"]
print(name)
end
end
end
end
function heading(text)
w, h = mon.getSize()
mon.setCursorPos((w-string.len(text))/2+1, 1)
mon.write(text)
end
fillTable()
while true do
mon.clear()
heading("Main Control Panel")
screen()
local e,side,x,y = os.pullEvent("monitor_touch")
print(x..":"..y)
checkxy(x,y)
sleep(.1)
end
Edited by