Jump to content




How do you make a button?


  • You cannot reply to this topic
5 replies to this topic

#1 denni199

  • Members
  • 14 posts
  • LocationDenmark

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.

#2 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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

#3 denni199

  • Members
  • 14 posts
  • LocationDenmark

Posted 02 February 2013 - 10:12 AM

View PostLyqyd, on 02 February 2013 - 10:03 AM, said:

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

#4 Lyqyd

    Lua Liquidator

  • Moderators
  • 8,465 posts

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.

#5 denni199

  • Members
  • 14 posts
  • LocationDenmark

Posted 02 February 2013 - 10:17 AM

Ah thank you!

#6 KingMachine

  • Members
  • 122 posts

Posted 02 February 2013 - 11:34 AM

I believe the correct answer is; "one piece of stone in a crafting box" (har har)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users