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

Button help

Started by Rougeminner, 03 July 2014 - 03:56 AM
Rougeminner #1
Posted 03 July 2014 - 05:56 AM
This is going to look like i am absolutely stupid but i need help with buttons :(/> . I have looked and looked on how to make them and i have even tried API's to do it for me (Here is the part where i will sound REALLY stupid) and i still can't figure it out. I am trying to build a Mac OSX and IOS like setup and i have got the basics down like the main directory, Boot screens, password locks and the backup program but the GUI has not even started to work. I need some help is there anyone out there who can simplify making buttons that don't terminate the program after you click once.





Rougeminner
NanoBob #2
Posted 03 July 2014 - 08:48 AM
To detect a mouse click you are going to need to use os.pullEvent()


-- This will wait for any event to happend.
event,button,x,y=os.pullEvent()
However we do not want it to trigger at any event, we only care about the mouse click event.

--You can specify which event you want to pull by the first argument at the pullEvent function.
event,button,x,y=os.pullEvent("mouse_click")

Now you have that you are gonna want to check where the user clicked and if it coincides with your ubbton


event,button,x,y=os.pullEvent("mouse_click")
if x>=buttonStart and x<=buttonEnd and y>=buttonBottom and y<= buttonTop then
    --Run whatever you want the button to do
end