Thread Tools Display Modes
04-15-18, 06:41 AM   #1
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 75
Need help with a hard trigger

Need your help guys, trying to get this trigger to work...

local localeicon = CreateFrame("Frame", "LocaleIcon", self)
localeicon:RegisterEvent("PLAYER_ENTERING_WORLD")
localeicon:RegisterEvent("PLAYER_TARGET_CHANGED")
localeicon:SetFrameLevel(self.Health:GetFrameLevel() + 6)
local localeicontexture = localeicon:CreateTexture(nil, "OVERLAY")
localeicon:SetScript("OnEvent", function(self, event, ...)


local servers = {
["Aggra(Português)"] = "Portuguese",

["AeriePeak"] = "English",
["Agamaggan"] = "English",
["Aggramar"] = "English",
["Ahn'Qiraj"] = "English",
["Al'Akir"] = "English"

-- > ALL OTHER SERVERS
-- ...
-- ...
}

if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
local serverName = select(2, UnitName("target"))
if servers[serverName]
and m.locale[servers[serverName]] then
locale_texture:SetTexture(m.locale[servers[serverName]])
return true
end
else



if (GetLocale() == "deDE") then
localeicontexture:SetTexture(m.locale.ruRU)

localeicontexture:Show()
return true
end

localeicontexture:Hide()
end
end)
localeicontexture:SetPoint('CENTER', self, 46.5, 136)
localeicontexture:SetSize(19,19)
localeicontexture:SetTexCoord(0, 1, 0, 1)
how do i insert the tables correctly?

My table file

m.locale = {
ptBR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
enGB = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
deDE = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_deDE",
itIT = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_itIT",
esES = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_esES",
ruRU = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ruRU",
frFR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_frFR",
}

Last edited by GreyFox777 : 04-15-18 at 06:58 AM.
  Reply With Quote
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
04-15-18, 09:42 AM   #3
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 75

local setRealmIcon = CreateFrame("Frame", "RealmIcon", self)
local setRealmIcon = function(self, event, ...)
local servers = {
["Aggra(Português)"] = "Portuguese",

["AeriePeak"] = "English",
["Agamaggan"] = "English",
["Aggramar"] = "English",
["Ahn'Qiraj"] = "English",
["Al'Akir"] = "English",
["Alonsus"] = "English",
...
...
...
...
["Ysondre"] = "French"
}
if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
local serverName = select(2, UnitName("player"))
if servers[serverName]
and m.locale[servers[serverName]] then
setRealmIcon:SetTexture(m.locale[servers[serverName]])
return true
end
end
end

setRealmIcon:RegisterEvent("PLAYER_ENTERING_WORLD", setRealmIcon)
setRealmIcon:RegisterEvent("PLAYER_TARGET_CHANGED", setRealmIcon)
Don't seems to be working

the error:

Interface\AddOns\oUF_lumen\units\target.lua:849: attempt to index local 'setRealmIcon' (a function value)

Last edited by GreyFox777 : 04-15-18 at 09:52 AM.
  Reply With Quote
04-15-18, 09:49 AM   #4
jukx
A Murloc Raider
 
jukx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2018
Posts: 7
For debugging (=making stuff work that doesn't work right now), I'd recommend installing BugSack and BugGrabber so you can see where the error is.

---

Also, you're calling m.locale[servers[serverName]] which won't work.
servers[serverName] returns something like "English" which is not a valid key in your table m.locale.
To make it work you'd have to match the keys to the content of the servers table:
Lua Code:
  1. m.locale = {
  2. Portuguese = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
  3. English = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
  4. -- ...
  5. }

---

Furthermore, if your question is how to insert the code for the table into the code above, just rename m.locale to locale and insert the table definition at the top, like this:

Lua Code:
  1. local locale = {
  2.     ptBR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
  3.     enGB = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
  4.     deDE = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_deDE",
  5.     itIT = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_itIT",
  6.     esES = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_esES",
  7.     ruRU = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ruRU",
  8.     frFR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_frFR",
  9. }
  10.  
  11. local localeicon = CreateFrame("Frame", "LocaleIcon", self)
  12. localeicon:RegisterEvent("PLAYER_ENTERING_WORLD")
  13. localeicon:RegisterEvent("PLAYER_TARGET_CHANGED")
  14. localeicon:SetFrameLevel(self.Health:GetFrameLevel() + 6)
  15. local localeicontexture = localeicon:CreateTexture(nil, "OVERLAY")
  16. localeicon:SetScript("OnEvent", function(self, event, ...)
  17.  
  18.     local servers = {
  19.         -- ...
  20.     }
  21.  
  22.     if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
  23.         local serverName = select(2, UnitName("target"))
  24.         if servers[serverName]
  25.             and m.locale[servers[serverName]] then
  26.             locale_texture:SetTexture(locale[servers[serverName]])
  27.             return true
  28.         end
  29.     else
  30.         -- ...

Last edited by jukx : 04-15-18 at 09:53 AM.
  Reply With Quote
04-15-18, 09:54 AM   #5
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 75
yes, it was already

m.locale = {
ptBR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
enGB = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
deDE = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_deDE",
itIT = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_itIT",
esES = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_esES",
ruRU = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ruRU",
frFR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_frFR",
Portuguese = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
English = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
German = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_deDE",
Italian = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_itIT",
Spanish = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_esES",
Russian = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ruRU",
French = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_frFR",

}
  Reply With Quote
04-15-18, 10:16 AM   #6
GreyFox777
A Cliff Giant
Join Date: Jan 2017
Posts: 75
Now, it has zero errors, but still not working...

local locale = {
ptBR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
enGB = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
deDE = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_deDE",
itIT = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_itIT",
esES = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_esES",
ruRU = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ruRU",
frFR = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_frFR",
}

local localeicon = CreateFrame("Frame", "LocaleIcon", self)
localeicon:RegisterEvent("PLAYER_ENTERING_WORLD")
localeicon:RegisterEvent("PLAYER_TARGET_CHANGED")
localeicon:SetFrameLevel(self.Health:GetFrameLevel() + 6)
local localeicontexture = localeicon:CreateTexture(nil, "OVERLAY")

localeicontexture:SetPoint('CENTER', self, 46.5, 136)
localeicontexture:SetSize(19,19)
localeicontexture:SetTexCoord(0, 1, 0, 1)

localeicon:SetScript("OnEvent", function(self, event, ...)

local servers = {
["Aggra(Português)"] = "Portuguese",

["AeriePeak"] = "English",
["Agamaggan"] = "English",
["Aggramar"] = "English",
...
...
...
["Varimathras"] = "French",
["Vol'jin"] = "French",
["Ysondre"] = "French"
}

if select(2, UnitName("target")) and select(2, UnitName("target")) ~= '' then
local serverName = select(2, UnitName("target"))
if servers[serverName]
and locale[servers[serverName]] then
localeicontexture:SetTexture(locale[servers[serverName]])
return true
end
end
end)


localeicontexture:Show()
localeicontexture:SetPoint('CENTER', self, 46.5, 136)
localeicontexture:SetSize(19,19)
localeicontexture:SetTexCoord(0, 1, 0, 1)


Uiiii it works now!

I forget to add
Portuguese = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ptBR",
English = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_enGB",
German = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_deDE",
Italian = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_itIT",
Spanish = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_esES",
Russian = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_ruRU",
French = "Interface\\AddOns\\oUF_lumen\\media\\Locale_flag_frFR",

Last edited by GreyFox777 : 04-15-18 at 10:20 AM.
  Reply With Quote
04-15-18, 10:36 AM   #7
Ammako
A Frostmaul Preserver
AddOn Author - Click to view addons
Join Date: Jun 2016
Posts: 256
Originally Posted by GreyFox777 View Post
Don't seems to be working

the error:
For the record, you created a frame under that var name there, and then overwrote it with a function right after. Hence the error, because your frame is gone and :SetTexture is not valid for functions.

You've changed that later and have it working now, but you need to be careful with variable names not to overwrite other important stuff.


Also, you can do localicon.texture:CreateTexture(name, layer) to create a texture for your frame, without having to declare a second local variable. What you did would work too, but this way is cleaner and more straightforward.

You can add pretty much anything you want to frames that way. It doesn't specifically have to be called ".texture" for it to work as a texture (lua variables are typeless, you put anything you want in them), but it is recommended to use descriptive variable names so that's why I use that as the example.
  Reply With Quote

WoWInterface » Featured Projects » oUF (Otravi Unit Frames) » Need help with a hard trigger


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off