I would suggest using a range to check whether a click that occurred was on your button.
If your button starts at the origin of the screen (1, 1), is 5 high, and extends to the end of the screen (50?), I would suggest doing something like this:
local button_xPos, button_yPos = 1, 1
local buttonWidth, buttonHeight = 50, 5
-- Checks whether or not the click at the given position was
-- within the range provided.
function wasClickOnRange(xClickPos, yClickPos, xRangeStart, yRangeStart, rangeWidth, rangeHeight)
return (xClickPos >= xRangeStart or xClickPos <= xRangeStart + rangeWidth) and
(yClickPos >= yRangeStart or yClickPos <= yRangeStart + rangeHeight)
end
-- A more specific function to check if a click was on our button.
function wasClickOnButton(xClickPos, yClickPos)
return wasClickOnRange(xClickPos, yClickPos, button_xPos, button_yPos, buttonWidth, buttonHeight)
end
-- Grabs a click, checks whether or not it was on the button, then
-- performs the appropriate action.
function handleClicks()
local event, mouseButton, xClickPos, yClickPos = os.pullEvent("mouse_click")
-- Check if the click we got was on our button.
if wasClickOnButton(xClickPos, yClickPos) then
-- Do whatever you want here.
end
end
I'd be glad to clarify any of the above code if you need some help.