This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Kohron's profile picture

Buttons not clicking

Started by Kohron, 02 March 2015 - 09:17 AM
Kohron #1
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


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
Bomb Bloke #2
Posted 02 March 2015 - 10:56 PM
It's "monitor_touch". You're otherwise waiting for an event that will never happen.

If there are other problems, get a fresh copy of the original script.
Kohron #3
Posted 03 March 2015 - 02:22 AM
Its always 1 letter lol, that fixed it.

Thank you
Kohron