MaLarsson |
08-21-14 01:37 PM |
Button:SetScript
I've been scratcing my head for a while trying to figure this out.
This code works:
Lua Code:
local btn = CreateFrame("Button", "DoTrackerLockBtn", menu, "UIPanelButtonTemplate") btnLock:SetText("Lock") btnLock:SetWidth(80) btnLock:ClearAllPoints() btnLock:SetPoint("TOPRIGHT", -110, -16) btnLock:SetScript("OnClick", function() print("test") end)
This code works aswell:
Lua Code:
local function printTest() print("test") end local btn = CreateFrame("Button", "DoTrackerLockBtn", menu, "UIPanelButtonTemplate") btnLock:SetText("Lock") btnLock:SetWidth(80) btnLock:ClearAllPoints() btnLock:SetPoint("TOPRIGHT", -110, -16) btnLock:SetScript("OnClick", function() printTest() end)
But this code does not work:
Lua Code:
local function printTest() print("test") end local btn = CreateFrame("Button", "DoTrackerLockBtn", menu, "UIPanelButtonTemplate") btnLock:SetText("Lock") btnLock:SetWidth(80) btnLock:ClearAllPoints() btnLock:SetPoint("TOPRIGHT", -110, -16) btnLock:SetScript("OnClick", printTest())
Why is this? It seems to me that in all three cases I send a function to the SetScript Method but the last on does not work. What am I missing?
Thanks in advance
Marcus Larsson
|