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

Dude os.pullEvent()

Started by magick, 12 March 2018 - 09:50 PM
magick #1
Posted 12 March 2018 - 10:50 PM
I copied this code to study it, and I can not understand the width of the mouse as it affects the event of touching a monitor

event,p1,p2,p3 = os.pullEvent()
  -- this line tells the computer to wait until
  -- an event happens. We are waiting for a
  -- touchscreen event
  
   if event=="monitor_touch" then
   -- this checks to see if the event was a
   -- touchscreen event
  
	 mouseWidth = p2 -- sets mouseWidth
	 mouseHeight = p3 -- and mouseHeight 
Bomb Bloke #2
Posted 13 March 2018 - 01:39 PM
http://www.computercraft.info/wiki/Os.pullEvent

http://www.computercraft.info/wiki/Monitor_touch_(event)

os.pullEvent() returns a sequence of values which depend on the type of event first found at the front of the event queue. If that's a monitor_touch event, then the first value is "monitor_touch", the second is the name of the peripheral it came from, and then come the x/y co-ords of the touch as the third and fourth values.

This snippet simply assigns those x/y co-ords to variables called mouseWidth and mouseHeight.