Code: Select all
function love.mousepressed(x, y, button)
for k, obj in pairs(Objects) do
if obj.objtype == "Button" and x > obj.xpos and x < obj.xpos + obj.width and y > obj.ypos and y < obj.ypos + obj.height and button == 1 then
obj[click]()
end
end
end
The function is added like so.
Code: Select all
function Lib.addFunc(objname, functype, func)
Objects[objname][functype] = func
end
Code: Select all
Lib.addFunc("MyButton", "click", function()
Lib.edit("MyLabel", "words", "BUTTON WORKED")
end)
So, when the button is clicked, it should run it's click function stored in the click variable, but it doesn't change the text when clicked, and doesn't run the function. If anyone understood, can they help?
By the way, if anyone needs so the the createButton function, here.
Code: Select all
Lib = {}
Objects = {}
function Lib.createButton(objname, x, y, h, w, stat, r, g, b)
Objects[objname] = {objtype = "Button", xpos = x, ypos = y, height = h, width = w, status = stat, red = r, green = g, blue = b, click = nil} --click is set to nil because it's added later with the Lib.addFunc function.
end