View Single Post
08-21-14, 01:37 PM   #1
MaLarsson
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Aug 2014
Posts: 13
Button:SetScript

I've been scratcing my head for a while trying to figure this out.
This code works:
Lua Code:
  1. local btn = CreateFrame("Button", "DoTrackerLockBtn", menu, "UIPanelButtonTemplate")
  2. btnLock:SetText("Lock")
  3. btnLock:SetWidth(80)
  4. btnLock:ClearAllPoints()
  5. btnLock:SetPoint("TOPRIGHT", -110, -16)
  6. btnLock:SetScript("OnClick", function() print("test") end)
This code works aswell:
Lua Code:
  1. local function printTest()
  2.     print("test")
  3. end
  4.  
  5. local btn = CreateFrame("Button", "DoTrackerLockBtn", menu, "UIPanelButtonTemplate")
  6. btnLock:SetText("Lock")
  7. btnLock:SetWidth(80)
  8. btnLock:ClearAllPoints()
  9. btnLock:SetPoint("TOPRIGHT", -110, -16)
  10. btnLock:SetScript("OnClick", function() printTest() end)
But this code does not work:
Lua Code:
  1. local function printTest()
  2.     print("test")
  3. end
  4.  
  5. local btn = CreateFrame("Button", "DoTrackerLockBtn", menu, "UIPanelButtonTemplate")
  6. btnLock:SetText("Lock")
  7. btnLock:SetWidth(80)
  8. btnLock:ClearAllPoints()
  9. btnLock:SetPoint("TOPRIGHT", -110, -16)
  10. 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
  Reply With Quote