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

[Lua] Control Panel Monitor?

Started by SNWLeader, 01 February 2013 - 09:08 AM
SNWLeader #1
Posted 01 February 2013 - 10:08 AM
I am trying to make a control panel monitor so that way instead of buttons for a shop, the large monitor will be touchscreen.


I wanted to know what the code is for detecting a touchscreen at certain points.

and is there a payment system that is currently working right now for computercraft?
king77 #2
Posted 01 February 2013 - 10:45 AM

local event, p1, p2, p3 = os.pullEvent()
if event == "monitor_touch" then
  print("Side: " .. p1 .. " x: " .. p2 .. " y: " .. p3)
end

edit: you might want to put it in a loop
SNWLeader #3
Posted 01 February 2013 - 10:51 AM
I kinda need it to detect a specific area.
Sorry for not telling this ahead of time.

local event, p1, p2, p3 = os.pullEvent()
if event == "monitor_touch" then
  print("Side: " .. p1 .. " x: " .. p2 .. " y: " .. p3)
end

edit: you might want to put it in a loop
ChunLing #4
Posted 01 February 2013 - 11:42 AM
if p1 == side and p2 <= maxX and p2 >= minX and p3 <= maxY and p3 >= minY then
–code to process a click
end
Jumbub1 #5
Posted 01 February 2013 - 11:44 AM
I am pretty sure if you do an if statement to detect the event AS well as the x and y pos; so p2 and p3.. Not sure if the x and y are full screens though.

Example:
local event, p1, p2, p3 = os.pullEvent()
if event == "monitor_touch" and p2 == <Xpos> and p3 == <Ypos> then
<Your outcome>
end
SNWLeader #6
Posted 03 February 2013 - 05:02 PM
Well that is not turing up well.
I made it so that if you pressed a or b on the screen they would print different messages………but I can press any place on the monitr and only get the message for the first one.
ChunLing #7
Posted 03 February 2013 - 08:43 PM
You can post the code if you need help with it.
blm768 #8
Posted 03 February 2013 - 08:44 PM
Hmm… Could you post the code you're using?

Never mind; looks like ChunLing said that just as I was preparing this post.
SNWLeader #9
Posted 05 February 2013 - 01:19 PM
I have the code to a point that it won't even post the message
here is the code

monitor = peripheral.wrap("right")
mside = "right"
local event, side, x, y = os.pullEvent()
local function writeGUI()
monitor.setCursorPos(1,1)
monitor.write("/ A /   / B /")
monitor.setCursorPos(1,3)
monitor.write("Please press one")
end
local function clearScreen()
monitor.clear()
writeGUI()
end
clearScreen()
while true do

  clearScreen()
if os.pullEvent() then
  if event == "monitor_touch" then
    if (x == 1 or x == 2 or x == 3 or x == 4 or x == 5 ) and y == 1 then
	  monitor.setCursorPos(1,4)
	  monitor.write("Stupid Shit")
	  sleep(1)
    elseif (x == 13 or x == 10 or x == 11 or x == 12 or x == 9) and y == 1 then
	  monitor.setCursorPos(1,4)
	  monitor.write("Shit Stupid")
	  sleep(1)
    end
  else
    monitor.setCursorPos(18, 3)
    monitor.write("Program functioning.")
    os.startTimer(2)
  end
end
end
SNWLeader #10
Posted 05 February 2013 - 01:41 PM
I remade the code, but now I have to press the area twice before the message appears.
here is the code.

local function writeGUI()
  monitor.setCursorPos(1,1)
  monitor.write("/a/ /b/")
  monitor.setCursorPos(1,2)
  monitor.write("Select one")
end
local function clearScreen()
  monitor.clear()
  writeGUI()
end
monitor = peripheral.wrap(mside)
mside = "right"

while true do
  clearScreen()
  local event, side, x, y = os.pullEvent("monitor_touch")
  os.pullEvent()
  if event == "monitor_touch" then
   if x == 1 or x == 2 or x == 3 then
	 if y == 1 then
	  monitor.setCursorPos(1,3)
	  monitor.write("Herbalife")
	  sleep(1)
	 end
   elseif x == 5 or x == 6 or x == 7 then
    if y == 1 then
	  monitor.setCursorPos(1,3)
	  monitor.write("But stud.")
	  sleep(1)
	 end
   end
end
end
SNWLeader #11
Posted 05 February 2013 - 01:43 PM
nevermind I removed the os.pullEvent() part and now the program works like it should.
Problem solved.
ON TO MAKING A SHOP WITH THIS!