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

Monitor Touch Screen Question

Started by mikes930, 04 May 2013 - 09:35 PM
mikes930 #1
Posted 04 May 2013 - 11:35 PM
I know you can get a touch on a monitor by using this code:
local event, <side>, x, y = os.pullEvent("monitor_touch)
but is there a way to after this line do like an
if x = 1 then
print ("1")
else
print ("no")
end
or something like that? I like to make my own programs but when it comes to touch screens I'm lost like lost lost….any help would be GREAT!
Lyqyd #2
Posted 05 May 2013 - 02:37 AM
Split into new topic.
angellus #3
Posted 05 May 2013 - 09:33 AM
So here is the link for the event: http://computercraft...r_touch_(event)

Run this and you will see how the event works better:

while true do
	local event, side, x, y = os.pullEvent("monitor_touch")
	print("event: " .. event)
	print("side: " .. side)
	print("(x, y): (" .. x .. ", " .. y .. ")")
end

You will have to use CTRL+T to terminate it. The os.pullEvent runs forever until the event happens. The monitor_touch event is fired when there is an Advanced Monitor connected to the computer and a player right-clicks it. It then returns the four variables once it does: event, side, x, and y. Event is the type of event it was (it will always be "monitor_touch" in this case). Side is the side the advanced monitor is connected on ("top", "bottom", "left", "right", "front" or "back"). X and Y are the coords of the position the player clicked.


So lets say you wanted to detect if a player clicked the top left of the screen, you would just do

local event, side, x, y = os.pullEvent("monitor_touch")
if (x == 1 and y == 1) then
	print("Player clicked top left corner")
else
	print("Player clicked (" .. x .. ", " .. y .. ")")
end
SkyyZZ #4
Posted 11 July 2013 - 02:11 AM
angellus, you have just explained to me in 5 minutes what an hour of wiki searches hasn't taught me.