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

mouse_click help

Started by kaioo1312, 26 November 2013 - 01:35 PM
kaioo1312 #1
Posted 26 November 2013 - 02:35 PM
I am currently making a program where number pad is printed on a screen. I want to detect a mouse click in a certain area but I dont know how. I looked on the wiki and it is confusing me and i dont know what to do. I need professional help!
Lyqyd #2
Posted 26 November 2013 - 02:47 PM
You're wanting to check whether a point (where the user clicked) is within a certain area, so all you need to do is ensure that the point is within the bounds of that area. You test the point's x coordinate against the minimum and maximum x boundaries (and the same with y), and if it is, act accordingly. This is pretty simple once it is broken down. How would you check that a number is at least as big as another? Or at most as big as a number? Those are your minimum and maximum comparisons.
TheOddByte #3
Posted 26 November 2013 - 03:20 PM
Well this isn't really that hard, But you should make it more clear what it is you don't understand, Is it the events? How you will if the mouse click was in bounds?
Anyways, I'm gonna be nice here and help you out

local evt, p1, mX, mY = os.pullEvent("mouse_click") --# Start with waiting for the event
--# Here it will check if you pressed between the x positon 1-10 and if the y position was 1
if mX >= 1 and mY <= 10 and mY == 1 then
    -- Some code here
end
Well this was just a simple example, This is often how I myself check if a button was clicked.
Zambonie #4
Posted 27 November 2013 - 10:38 PM
Ive mad a small example:

--Lets say this is the button to press '1'
--Button 1 will be a 3x3 square at position 2,2
local event, button, x, y = os.pullEvent("mouse_click") --This sets the event to wait for a mouse click
--Here it will check if you pressed were 1 is.
if x >= 2 and x <= 5 and y >= 2 and y <= 5 and button == 1 then --If the x pos is between 2 -5 and the y pos is between 2-5 and if you clicked the button with the left click.
--Than you put some code here
end