to make it work on if a player clicks a button on their mouse you have to use an os event. i can help you with it if you would like
i cant exactly help right now so tell me when youre on
If you want to get the x and y coordinate of the mouse when clicked, you use the os.pullEvent function:
--# make a new button
local button = {
x = 10, y = 10, w = 10, h = 5, func = function()
--# we call this function when the button is clicked
print("button clicked")
end
}
--# waits until mouse is pressed and gets data about the click
local event, mouseButton, mouseX, mouseY = os.pullEvent("mouse_click")
--# check if our button is clicked
if mouseX>=button.x and mouseY>=button.y then
# mouse was clicked right and below the button
if mouseX<button.x+button.w and mouseY<button.y+button.h then
--# mouse was clicked left and above the bottom right corner of the button
--# run the button function
button.func()
end
end
Here is
more information about os.pullEvent and which events are there.
Later you can make a function to make a new button:
--# function to make a new button, takes x, y, w, h and func and returns button
local function newButton(x, y, w, h, func)
return {
x=x,y=y,w=w,h=h,func=func,
draw = function(self)
--# use the paintutils api to draw a box
paintutils.drawFilledBox(self.x, self.y, self.x+self.w-1, self.y+self.h-1, colors.lightBlue)
end,
update = function(self, mouseX, mouseY)
if mouseX>=self.x and mouseY>=self.y and mouseX<self.x+self.w and mouseY<self.y+self.h then
self.func()
end
end
end
--# make a new button
local button = newButton(10, 10, 10, 5, function()
print("pressed")
end)
--# draw button
button:draw()
--# get events once again
local event, mouseButton, mouseX, mouseYos.pullEvent("mouse_click")
button:update(mouseX, mouseY)