If the touchscreen will have multiple buttons, I would suggest using a table:
--[[ Declare a table with the buttons that will be printed,
with it's own Text Colour and Background Colour and
unique x and y values.
t = {
{text = "Button 1", x = 1, y = 1, txtCol = colours.red, bgCol = colours.lime},
{text = "Button 2", x = 1, y = 2, txtCol = colours.red, bgCol = colours.lime},
{text = "Button 3", x = 1, y = 3, txtCol = colours.red, bgCol = colours.lime}
}
mon = peripherial.wrap("side")
function writeButtons(_table)
for i, v in pairs(_table) do
term.setCursorPos(v.x, v.y)
term.setTextColour(v.txtCol)
term.setBackgroundColour(v.bgCol)
write(v.text)
end
end
function isValidClick(_table, mx, my)
for i, v in pairs(_table) do
if mx >= v.x and mx <= (v.x + #v.text) and my == v.y then
return true, v.text
end
end
return false, nil
end
writeButtons(t)
while true do
_, but, x, y = os.pullEvent("monitor_touch")
bClick, option = isValidClick(t, x, y)
if bClick then
-- Yes, it's a valid click. Now let's do something with the returned text 'option'
if option == "Button 1" then -- button 1...
elseif option == "Button 2" then
elseif option == "Button 3" then
end
end
Something like that would be the easiest way. If you need me to explain anything, feel free to ask :)/>