Hi,
I created a constructor function to create an object. Inside this function, a function named "onClick" is defined and this function is mandatory because I am writing a DX library. However, when I create the object, even if I define the onClick function inside the object, it always returns the value as "nil". I did a few tests, it has nothing to do with mouse locations or anything else. The button click function works, the only problem is that I cannot define the onClick function.
-- // Button.lua constructor:
function createButton(config)
local self = setmetatable({}, Button)
self.x = config.x
self.y = config.y
self.width = config.width
self.height = config.height
self.text = config.text or "Button"
self.color = config.color or "blue"
self.fade = config.fade ~= false
self.onClick = config.onClick or false -- // This always returns false, even if I added onClick function.
self.alpha = self.fade and 0 or 255
self.fade_step = 15
self.visible = true
self.currentColor = Theme.colors.button[self.color].background
table.insert(activeButtons, self)
return self
end
-- // Example.lua, example for using:
loadstring(exports.ui:injectModules())()
local btn = Button({
x = 20,
y = 60,
width = 100,
height = 30,
text = "Click",
color = "blue",
fade = true,
onClick = function(self)
outputChatBox("Clicked the button.") -- // It's not working.
end
})