Posted 02 March 2015 - 10:17 AM
I am trying to use a touch screen monitor to create 2 buttons, each switching something else off. The screen shows the buttons, but when i click them (or anywhere on the screen for that matter) it doesn't switch them to the other position (on/off). I would be thankful if someone would be able to help me out with this because i can't figure it out for the life of me.
Kohron
Kohron
local cableSide = "right"
local mon = peripheral.wrap("top")
mon.setTextColor(colors.white)
mon.setBackgroundColor(colors.black)
mon.clear()
local xLen, yLen = mon.getSize()
local myEvent
-- Menu Items.
local switches = {
["Lights"] = {color = colors.white, screenRow = 1},
["Ritual"] = {color = colors.red, screenRow = 5}}
-- Initial Menu Render:
for key,value in pairs(switches) do
mon.setBackgroundColor(colors.black)
mon.setCursorPos(2,value.screenRow)
mon.write(key)
mon.setCursorPos(xLen-5,value.screenRow)
if colours.test(rs.getBundledOutput(cableSide),value.color) then
mon.setBackgroundColor(colors.green)
mon.write(" On ")
else
mon.setBackgroundColor(colors.red)
mon.write(" Off ")
end
end
-- Main program loop.
while true do
myEvent = {os.pullEvent("moniter_touch")}
for key,value in pairs(switches) do if myEvent[4] == value.screenRow then
mon.setCursorPos(xlen-5,value.screenRow)
if not colours.test(rs.getBundledOutput(cableSide), value.color) then
mon.setBackgroundColor(colors.green)
mon.write(" On ")
rs.setBundledOutput(cableSide,colors.combine(rs.getBundledOutput(cableSide),value.color))
else
mon.setBackgroundColor(colors.red)
mon.write(" Off ")
rs.setBundledOutput(cableSide,colors.subtract(rs.getBundledOutput(cableSide),value.color))
end
break
end end
end