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

How do you make a button?

Started by denni199, 02 February 2013 - 08:59 AM
denni199 #1
Posted 02 February 2013 - 09:59 AM
Before anything i just wanna say if it is possible keep this as simple as you can. I am still learning and am by no means skilled. This doesn't mean i don't know nothing but just to be sure keep it simple.

I would like to have an area of the screen to check for clicks but i don't know how?
How can i define an area to check for mouse clicks?
I know how to check one point but how do i do an area.
By point i mean like this:

while true do
event, button, x, y = os.pullEvent(mouse_click)

if x == 1 and y == 1 then
print("Hello World")
end

To be more accurate i want to make a button.
Lyqyd #2
Posted 02 February 2013 - 10:03 AM
Split into new topic.

You simply check if the click is between the bounds of your button:

if x >= 2 and x <= 10 and y >= 2 and y <= 4 then
denni199 #3
Posted 02 February 2013 - 10:12 AM
Split into new topic.

You simply check if the click is between the bounds of your button:

if x >= 2 and x <= 10 and y >= 2 and y <= 4 then

Oh okay. I'll test it in-game and fiddle around with the numbers and see what happends but feel free to explain it to me anyway :)/>
I think i understand it.
So if the mouse clicked x and y is somewhere inside the button which could be x: 2 - 10 and y: 2 - 4
Lyqyd #4
Posted 02 February 2013 - 10:16 AM
Yep. Any x value between 2 and 10 and any y value between 2 and 4 meet the criteria (these are, of course, the bounds of the button), while other clicks do not.
denni199 #5
Posted 02 February 2013 - 10:17 AM
Ah thank you!
KingMachine #6
Posted 02 February 2013 - 11:34 AM
I believe the correct answer is; "one piece of stone in a crafting box" (har har)