Thread Tools Display Modes
04-16-11, 12:24 PM   #1
SignOfDoom
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 18
Got a problem comparing strings

Hi
My AddOn does compare an yell message with a database of pre defined strings. The problem is that while fighting Anraphet, for example, the first yell, the long one, doesnt work, but hte other are working. Rajh on the other hand doesnt work at all and I dont have any idea why.
I dont get any LUA-Error if this occurs.

lua Code:
  1. function bsp_hoo(bsp_stringcheck,bsp_datayeller)
  2.  
  3.     local bsp_datasoundfile
  4.  
  5.     if bsp_datayeller == "Anraphet" then
  6.     print("ana")
  7.         if bsp_stringcheck == L.anraphet[1] then
  8.             bsp_datasoundfile=bsp_Database.anraphet[1]
  9.         elseif bsp_stringcheck == L.anraphet[2] then
  10.             bsp_datasoundfile=bsp_Database.anraphet[2]
  11.         elseif bsp_stringcheck == L.anraphet[3] then
  12.             bsp_datasoundfile=bsp_Database.anraphet[3]
  13.         elseif bsp_stringcheck == L.anraphet[4] then
  14.             bsp_datasoundfile=bsp_Database.anraphet[4]
  15.         elseif bsp_stringcheck == L.anraphet[5] then
  16.             bsp_datasoundfile=bsp_Database.anraphet[5]
  17.         elseif bsp_stringcheck == L.anraphet[6] then
  18.             bsp_datasoundfile=bsp_Database.anraphet[6]
  19.         elseif bsp_stringcheck == L.anraphet[7] then
  20.             bsp_datasoundfile=bsp_Database.anraphet[7]
  21.         end
  22.     elseif bsp_datayeller == "Rajh" then
  23.         print("rajh")
  24.         if bsp_stringcheck == L.rajh[1] then
  25.             bsp_datasoundfile=bsp_Database.rajh[1]
  26.         elseif bsp_stringcheck == L.rajh[2] then
  27.             bsp_datasoundfile=bsp_Database.rajh[2]
  28.         elseif bsp_stringcheck == L.rajh[3] then
  29.             bsp_datasoundfile=bsp_Database.rajh[3]
  30.         elseif bsp_stringcheck == L.rajh[4] then
  31.             bsp_datasoundfile=bsp_Database.rajh[4]
  32.         elseif bsp_stringcheck == L.rajh[5] then
  33.             bsp_datasoundfile=bsp_Database.rajh[5]
  34.  
  35.         end
  36.         end
  37.     return bsp_datasoundfile;
  38. end
This is the code wich choses what bsp_datasoundfile should contain.
I can see "ana" or "rajh" everytime one of them yells. but "bsp_datasoundfile" is nil

predefined:
lua Code:
  1. --Part1
  2. if not L then
  3.     L={}
  4. end
  5. L.anraphet={
  6.     [1]="Anraphet unit shutting down...";
  7.     [2]="Purge of unauthorized entities commencing.";
  8.     [3]="This unit has been activated outside normal operating protocols. Downloading new operational parameters. Download complete. Full unit self defense routines are now active. Destruction of foreign units in this system shall now commence.";
  9.     [4]="Target Annihilated.";
  10.     [5]="Purge Complete.";
  11.     [6]="Alphabeams activated. Target tracking commencing.";
  12.     [7]="Omega Stance activated. Annihilation of foreign unit is now imminent.";
  13. };
  14. L.rajh={
  15.     [1]="Blazing rays of light, take me!";
  16.     [2]="Defilers! Wretches! Fiends! Begone from here!";
  17.     [3]="Can you feel it? The blessed warmth of the sun?";
  18.     [4]="I send you to your deity.";
  19.     [5]="I take this life as an offering!";
  20. };
  21. --Part 2
  22. if not bsp_Database then
  23.     bsp_Database={}
  24. end
  25.     bsp_Database.rajh={
  26.         [1]="Sound\\Creature\\Rajh\\VO_HO_Rajh_Death01.ogg";
  27.         [1]="Sound\\Creature\\Rajh\\VO_HO_Rajh_Engage01.ogg";
  28.         [1]="Sound\\Creature\\Rajh\\VO_HO_Rajh_Event01.ogg";
  29.         [1]="Sound\\Creature\\Rajh\\VO_HO_Rajh_Slay01.ogg";
  30.         [1]="Sound\\Creature\\Rajh\\VO_HO_Rajh_Slay02.ogg";
  31.     };
  32.     bsp_Database.anraphet={
  33.         [1]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Death01.ogg";
  34.         [2]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Engage01.ogg";
  35.         [3]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Intro01.ogg";
  36.         [4]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Slay01.ogg";
  37.         [5]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Slay02.ogg";
  38.         [6]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Special01.ogg";
  39.         [7]="Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Special02.ogg";
  40.         };
I checked everything double but cant sill find any mistake. I hope someone has an idea.

Last edited by SignOfDoom : 04-16-11 at 02:50 PM.
  Reply With Quote
04-16-11, 02:30 PM   #2
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
The first block of code, I don't see any problem with. From what you're describing, it's matching the mob, but none of the messages. Possible things to check would be spelling or spacing. The first few times you're checking a message against a stored string, you'll run into a few problems trying to get them to match so it'll work.

To clean it up a bit and possibly to expand, you should look into looping the check.
lua Code:
  1. function bsp_hoo(msg,mob)
  2.     mob=mob:lower();--  Change to a case-insensitive form
  3.     if not bsp_Database[mob] or not L[mob] then return nil; end--   No data for mob
  4.  
  5.     for i,j in ipairs(L[mob]) do--  Loop through mob messages
  6.         if msg==j then
  7.             return bsp_Database[mob][i];--  Return with sound file
  8.         end
  9.     end
  10. end





The second block of code, I'm noticing that all the keys for "Rajh" are all 1. To make it a little easier, if all the keys are sequential, you don't need to define them. Just make sure the order matches and they'll get the correct keys.

For example, these produce the same result.
lua Code:
  1. tbl={
  2.     [1]="a";
  3.     [2]="b";
  4. };
lua Code:
  1. tbl={
  2.     "a";
  3.     "b";
  4. };





Also, be mindful of other addons running as well that might interfere with your code. I would suggest breaking away from the L namespace and work with your own. This table is commonly used in Ace addons for localizations and changing the common format for your own may break other addons or cause yours to break due to conflicts.
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-16-11 at 02:47 PM.
  Reply With Quote
04-16-11, 02:36 PM   #3
SignOfDoom
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 18
i didnt noticed that rajh had only "1s". I also thought about building in a for loop, but i think my way will be enough for the mooment. but this does not cause the problem.
i would just hear the same sound for every yell
this is the code wich uses these functions:

lua Code:
  1. --File 1
  2. bsp_prefix = "[BossSpeech]: "
  3. local bsp_yellmessage
  4. local bsp_yeller
  5. local bsp_soundfilepath
  6.  
  7. --SLASH_clitracker1= "/bsp"
  8. --SLASH_clitracker2= "/bsp"
  9.  
  10. local bsp_frame = CreateFrame("Frame")
  11. bsp_frame:RegisterEvent("CHAT_MSG_MONSTER_YELL")
  12. bsp_frame:RegisterEvent("ADDON_LOADED")
  13.  
  14. --SlashCmdList["clitracker"] = function(msg)
  15.  
  16. --end
  17.  
  18. local function bsp_onyell(bsp_yellmessage,bsp_yeller)
  19.     --print("onyell")
  20.     --print(bsp_yeller)
  21.     --print(bsp_yellmessage)
  22.     bsp_soundfilepath=bsp_getfromdata(bsp_yeller,bsp_yellmessage)
  23.     print(bsp_soundfilepath)
  24.     if bsp_soundfilepath ~= nil then
  25.         --print(bsp_soundfilepath)
  26.         PlaySoundFile(bsp_soundfilepath, "Master")
  27.         bsp_soundfilepath = nil
  28.         --print(bsp_soundfilepath)
  29.     end
  30.     --print("fertig")
  31. end
  32.  
  33. local function bsp_handler(self, event, ...)
  34.     --print("yell1")
  35.     if event == "CHAT_MSG_MONSTER_YELL" then
  36.         --print("yell")
  37.         bsp_onyell((select(1,...)),(select(2,...)))
  38.     elseif event == "ADDON_LOADED" then
  39.         if select(1,...) == "BossSpeech" then
  40.         end
  41.     end
  42. end
  43.  
  44. bsp_frame:SetScript("OnEvent", bsp_handler)
lua Code:
  1. --File 2
  2. function bsp_getfromdata(bsp_databaseryeller,bsp_datayellmessage)
  3.    
  4.     --------
  5.     --CATA
  6.     --------
  7.     if GetRealZoneText() == "Blackrock Caverns" then
  8.     --  print("richtige zone")
  9.         bsp_datapath=bsp_brc(bsp_datayellmessage,bsp_databaseryeller)
  10.     elseif  GetRealZoneText() == "Grim Batol" then
  11.         bsp_datapath=bsp_gb(bsp_datayellmessage,bsp_databaseryeller)
  12.     elseif  GetRealZoneText() == "Halls of Origination" then
  13.         bsp_datapath=bsp_hoo(bsp_datayellmessage,bsp_databaseryeller)
  14. --  elseif  GetRealZoneText() == "Lost City of the Tol'vir" then
  15. --      bsp_datapath=bsp_lcott(bsp_datayellmessage,bsp_databaseryeller)
  16. --  elseif  GetRealZoneText() == "Shadowfang Keep" then
  17. --      bsp_datapath=bsp_sfk(bsp_datayellmessage,bsp_databaseryeller)
  18. --  elseif  GetRealZoneText() == "The Deadmines" then
  19. --      bsp_datapath=bsp_dm(bsp_datayellmessage,bsp_databaseryeller)
  20. --  elseif  GetRealZoneText() == "The Stonecore" then
  21. --      bsp_datapath=bsp_score(bsp_datayellmessage,bsp_databaseryeller)
  22. --  elseif  GetRealZoneText() == "The Vortex Pinnacle" then
  23. --      bsp_datapath=bsp_vortex(bsp_datayellmessage,bsp_databaseryeller)
  24. --  elseif  GetRealZoneText() == "Throne of the Tides" then
  25. --      bsp_datapath=bsp_tides(bsp_datayellmessage,bsp_databaseryeller)
  26.     end
  27.    
  28.     --------"Hellfire Ramparts"
  29.     --BC
  30.     --------
  31.     if GetRealZoneText() == "Hellfire Ramparts" then
  32.     --  print("richtige zone")
  33.         bsp_datapath=bsp_hfr(bsp_datayellmessage,bsp_databaseryeller)
  34.     end
  35.     return bsp_datapath;
  36. end
I also sometimes get a problem in line 31. so that my addon doesnt scan for yells in hellfire ramparts. i doubleckecked the spelling. I also wrote an addon that saves all yells that are made, so i am sure the spelling is right

Last edited by SignOfDoom : 04-16-11 at 02:54 PM.
  Reply With Quote
04-16-11, 02:55 PM   #4
daylesan
A Fallenroot Satyr
Join Date: Feb 2011
Posts: 22
May i suggest a simpler code structure:

Lua Code:
  1. L = {}
  2. L["anraphet"] = {
  3.      ["Anraphet unit shutting down..."] = "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Death01.ogg",
  4.      ["Purge of unauthorized entities commencing."] = "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Engage01.ogg",
  5. }
  6. L["rajh"] = {
  7.     -- similar stuff as above
  8. }

The sound files can then be accessed as follows

Lua Code:
  1. function bsp_hoo(bsp_stringcheck,bsp_datayeller)
  2.      return L.bsp_datayeller.bsp_stringcheck
  3. end

Though the function probably isn't even necessary anymore.

Edit: changed the L.rahj to L["rajh"] since it has to be a string.

Last edited by daylesan : 04-16-11 at 03:02 PM.
  Reply With Quote
04-16-11, 05:03 PM   #5
SignOfDoom
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 18
I still dont know what caused this problem but after i minimized the code (tanks to daylesan) everything i tested till now works.
Does someone know if there is a maximum lengh of a tabke key?
  Reply With Quote
04-16-11, 05:45 PM   #6
SDPhantom
A Pyroguard Emberseer
 
SDPhantom's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2006
Posts: 2,323
Originally Posted by SignOfDoom View Post
Does someone know if there is a maximum lengh of a tabke key?
There shouldn't be.



Here's what I have so far:

localization.lua
lua Code:
  1. local name,addon=...;
  2. local locale=GetLocale();
  3.  
  4. if locale=="enGB" then
  5. --  Example: Setup for British client
  6. else
  7. --  Default to US client
  8.     addon.MobLocale={
  9.         ["Halls of Origination"]={
  10.             ["Anraphet"]={
  11.                 ["Anraphet unit shutting down..."]=
  12.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Death01.ogg";
  13.                 ["Purge of unauthorized entities commencing."]=
  14.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Engage01.ogg";
  15.                 ["This unit has been activated outside normal operating protocols. Downloading new operational parameters. Download complete. Full unit self defense routines are now active. Destruction of foreign units in this system shall now commence."]=
  16.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Intro01.ogg";
  17.                 ["Target Annihilated."]=
  18.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Slay01.ogg";
  19.                 ["Purge Complete."]=
  20.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Slay02.ogg";
  21.                 ["Alphabeams activated. Target tracking commencing."]=
  22.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Special01.ogg";
  23.                 ["Omega Stance activated. Annihilation of foreign unit is now imminent."]=
  24.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Special02.ogg";
  25.             };
  26.             ["Rajh"]={
  27.                 ["Blazing rays of light, take me!"]=
  28.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Death01.ogg";
  29.                 ["Defilers! Wretches! Fiends! Begone from here!"]=
  30.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Engage01.ogg";
  31.                 ["Can you feel it? The blessed warmth of the sun?"]=
  32.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Event01.ogg";
  33.                 ["I send you to your deity."]=
  34.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Slay01.ogg";
  35.                 ["I take this life as an offering!"]=
  36.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Slay02.ogg";
  37.             };
  38.         };
  39.     }
  40. end

bsp.lua
lua Code:
  1. local name,addon=...;
  2. local title=select(2,GetAddOnInfo(name));-- Localized title if set in ToC
  3.  
  4. local frame=CreateFrame("Frame");
  5. frame:RegisterEvent("CHAT_MSG_MONSTER_YELL");
  6. frame:SetScript("OnEvent",function(self,event,...)
  7. --  You can add more events if you wish
  8.     if event=="CHAT_MSG_MONSTER_YELL" then
  9.         local zone,msg,mob=GetRealZoneText(),...;-- Note "..." will fill both msg and mob as long as it's last in the list
  10.  
  11. --      Table existance needs to be checked in this order or attempt to index nil error can be thrown
  12.         if addon.MobLocale[zone] and addon.MobLocale[zone][mob] and addon.MobLocale[zone][mob][msg] then
  13.             PlaySoundFile(addon.MobLocale[zone][mob][msg]);--   Play Sound
  14.         end
  15.     end
  16. end);

This should work as long as all the strings match up.
Make sure you load localization.lua before bsp.lua.
This code has no global footprint and uses the shared table WoW creates specifically for your addon
__________________
WoWInterface AddOns
"All I want is a pretty girl, a decent meal, and the right to shoot lightning at fools."
-Anders (Dragon Age: Origins - Awakening)

Last edited by SDPhantom : 04-16-11 at 05:50 PM.
  Reply With Quote
04-16-11, 06:07 PM   #7
SignOfDoom
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2010
Posts: 18
Originally Posted by SDPhantom View Post
There shouldn't be.



Here's what I have so far:

localization.lua
lua Code:
  1. local name,addon=...;
  2. local locale=GetLocale();
  3.  
  4. if locale=="enGB" then
  5. --  Example: Setup for British client
  6. else
  7. --  Default to US client
  8.     addon.MobLocale={
  9.         ["Halls of Origination"]={
  10.             ["Anraphet"]={
  11.                 ["Anraphet unit shutting down..."]=
  12.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Death01.ogg";
  13.                 ["Purge of unauthorized entities commencing."]=
  14.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Engage01.ogg";
  15.                 ["This unit has been activated outside normal operating protocols. Downloading new operational parameters. Download complete. Full unit self defense routines are now active. Destruction of foreign units in this system shall now commence."]=
  16.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Intro01.ogg";
  17.                 ["Target Annihilated."]=
  18.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Slay01.ogg";
  19.                 ["Purge Complete."]=
  20.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Slay02.ogg";
  21.                 ["Alphabeams activated. Target tracking commencing."]=
  22.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Special01.ogg";
  23.                 ["Omega Stance activated. Annihilation of foreign unit is now imminent."]=
  24.                     "Sound\\Creature\\Anraphet\\VO_HO_Anraphet_Special02.ogg";
  25.             };
  26.             ["Rajh"]={
  27.                 ["Blazing rays of light, take me!"]=
  28.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Death01.ogg";
  29.                 ["Defilers! Wretches! Fiends! Begone from here!"]=
  30.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Engage01.ogg";
  31.                 ["Can you feel it? The blessed warmth of the sun?"]=
  32.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Event01.ogg";
  33.                 ["I send you to your deity."]=
  34.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Slay01.ogg";
  35.                 ["I take this life as an offering!"]=
  36.                     "Sound\\Creature\\Rajh\\VO_HO_Rajh_Slay02.ogg";
  37.             };
  38.         };
  39.     }
  40. end

bsp.lua
lua Code:
  1. local name,addon=...;
  2. local title=select(2,GetAddOnInfo(name));-- Localized title if set in ToC
  3.  
  4. local frame=CreateFrame("Frame");
  5. frame:RegisterEvent("CHAT_MSG_MONSTER_YELL");
  6. frame:SetScript("OnEvent",function(self,event,...)
  7. --  You can add more events if you wish
  8.     if event=="CHAT_MSG_MONSTER_YELL" then
  9.         local zone,msg,mob=GetRealZoneText(),...;-- Note "..." will fill both msg and mob as long as it's last in the list
  10.  
  11. --      Table existance needs to be checked in this order or attempt to index nil error can be thrown
  12.         if addon.MobLocale[zone] and addon.MobLocale[zone][mob] and addon.MobLocale[zone][mob][msg] then
  13.             PlaySoundFile(addon.MobLocale[zone][mob][msg]);--   Play Sound
  14.         end
  15.     end
  16. end);

This should work as long as all the strings match up.
Make sure you load localization.lua before bsp.lua.
This code has no global footprint and uses the shared table WoW creates specifically for your addon
Thanks for your help. I think everything works now.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Got a problem comparing strings


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