View Single Post
04-15-18, 08:40 AM   #2
jukx
A Murloc Raider
 
jukx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 7
You can just pass a function as a second argument to RegisterEvent:

Lua Code:
  1. local doStuff = function(self, event, ...)
  2.     local servers = {
  3.         ["Aggra(Português)"] = "Portuguese",
  4.     }
  5.     ...
  6. end
  7.  
  8. localeicon:RegisterEvent("PLAYER_ENTERING_WORLD", doStuff)
  9. localeicon:RegisterEvent("PLAYER_TARGET_CHANGED", doStuff)

---

edit for verbosity:

Right now you're passing function that's supposed to be executed as a callback to SetScript:
Lua Code:
  1. localeicon:RegisterEvent("PLAYER_ENTERING_WORLD")
  2. localeicon:RegisterEvent("PLAYER_TARGET_CHANGED")
  3. localeicon:SetScript("OnEvent", function(self, event, ...)
  4.  
  5.     local servers = {
  6.         -- ...
  7.     }
  8.  
  9.     if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
  10.         -- ...
  11.     end
  12. end)

Since oUF rewrote the RegisterEvent function, this might not work out as planned. Instead, you can just define that function locally and pass it as a second argument to RegisterEvent() like I showed above:
Lua Code:
  1. local setRealmIcon = function(self, event, ...)
  2.     local servers = {
  3.         -- ...
  4.     }
  5.  
  6.     if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
  7.         -- ...
  8.     end
  9. end
  10.  
  11. localeicon:RegisterEvent("PLAYER_ENTERING_WORLD", setRealmIcon)
  12. localeicon:RegisterEvent("PLAYER_TARGET_CHANGED", setRealmIcon)

Last edited by jukx : 04-15-18 at 09:11 AM.
  Reply With Quote