m = term
--m = peripheral.wrap("top")
if m == term then
detect = "click"
else
detect = "touch"
end
local btns = {
["btn1"] ={
["xMin"] = 1,
["xMax"] = 10,
["yMin"] = 1,
["yMax"] = 5,
["text"] = "Start!",
["active"] = false,
},
-- ["btn2"] = {
-- ["xMin"] = 11,
-- ["xMax"] = 10,
-- ["yMin"] = 1,
-- ["yMax"] = 5,
-- ["text"] = "Quit",
-- ["active"] = false,
-- }
}
m.clear()
m.setCursorPos(1,7)
m.setBackgroundColor(colors.green)
function findCenter()
xPos = math.floor((btns["btn1"]["xMax"]- btns["btn1"]["xMin"] - string.len(btns["btn1"]["text"])) /2)+1
yPos = math.floor((btns["btn1"]["yMin"] + btns["btn1"]["yMax"])/2)
end
function createBtn(btn)
xMin = btns["btn1"]["xMin"]
xMax = btns["btn1"]["xMax"]
yMin = btns["btn1"]["yMin"]
yMax = btns["btn1"]["yMax"]
if btns[btn]["active"] == false then
color = colors.red
else
color = colors.lime
end
m.setBackgroundColor(color)
for i = yMin, yMax do
m.setCursorPos(xMin, i)
if i == yPos then
for k = 0,xMax-xMin-string.len(text)+1 do
if k == xPos then
m.write(text)
else
m.write(" ")
end
end
else
for o = xMin, xMax do
m.write(" ")
end
end
end
m.setBackgroundColor(colors.black)
end
function click()
if detect == "click" then
event, button, x, y = os.pullEvent("mouse_click")
elseif detect == "touch" then
event, button, x, y = os.pullEvent("monitor_touch")
end
if x >= btns["btn1"]["xMin"] and x <= btns["btn1"]["xMax"] and y >= btns["btn1"]["yMin"] and y <= btns["btn1"]["yMax"] then
clicked = Start
--elseif x >=
end
end
findCenter("btn1")
createBtn("btn1")
term.setCursorPos(1,10)
If someone could locate the problem that would be great!
Help is appreciated!
Thanks!












