View Single Post
02-26-13, 07:31 AM   #7
shalom69
A Fallenroot Satyr
Join Date: Feb 2013
Posts: 22
Originally Posted by F16Gaming View Post
Or just
Lua Code:
  1. if msg:lower():find("blizzard") then


Edit: They do the same thing really, it's just different ways to do it.
Hmm I'm not familiar with that syntax. The strfind entry was on the WOW API reference so I could see how Haleth's example worked. I guess in this example "find("string") is a command native to lua for the msg argument?

It's good to know different ways to do stuff I'll file that somewhere in the "look up later" bin in case I need it sometime.

BTW can anyone explain to me why nesting IFs doesn't work in the following code?

I actually was using the code in the first post to test if I had the semantics right for handling and sorting through chat events. I'm practicing writing a noob addon that gives me alerts on my main while multiboxing. It's rudimentary code including the /say and raid alerts but wondering why if-if-if doesn't work in the following code. if-elseif-elseif works. is it because CHAT_MSG_SAY is and can only be 1 incident? if someone could take a min and explain why I can't use if-if that would be awesome. The chat messages received in the code are generated in another frame that registers events (autofollow_end, player_regen_disbled etc)

Code:
LeaderMessageHandlerFrame = CreateFrame("Frame")
LeaderMessageHandlerFrame:RegisterEvent("CHAT_MSG_SAY")
LeaderMessageHandlerFrame:SetScript("OnEvent", function(self, event, msg, sender, ...)
  if thisIsLeadWindow then
    if (msg == "NO LONGER FOLLOWING")  then
      RaidNotice_AddMessage(RaidWarningFrame, sender .." NO LONGER FOLLOWING", ChatTypeInfo["RAID_WARNING"])
    elseif (msg == "AGRO" and notUnitAffectingCombat("player"))  then
      RaidNotice_AddMessage(RaidWarningFrame, sender .." HAS AGRO", ChatTypeInfo["RAID_WARNING"])
    elseif (strfind(strlower(msg), "target is")) then
      local _,_,_, cloneTargetName = strsplit(" ", msg, 4)
       local myTargetName = (UnitName("playertarget"))
       if (cloneTargetName  ~= myTargetName and UnitIsFriend("player",cloneTargetName)==nil) then
         RaidNotice_AddMessage(RaidWarningFrame, sender .." IS ON DIFFERENT TARGET (".. cloneTargetName..")", ChatTypeInfo["RAID_WARNING"])
       end
    elseif (msg == "I AM UNDER ATTACK" and sender ~=UnitName("player"))  then
      print(sender)
      RaidNotice_AddMessage(RaidWarningFrame, sender .." IS UNDER ATTACK", ChatTypeInfo["RAID_WARNING"])
    end
  end
end)
also the following function for that thisIsLeadWindow check (I have LeaderFlagToggle function bound to a key through bindings.xml to tell the addon if it's running on a clone or the main window)

Code:
function LeaderFlagToggle()
  if not thisIsLeadWindow then
   thisIsLeadWindow = "true"
  else
   thisIsLeadWindow = "nil"
  end
end

BINDING_HEADER_CLONESTATES = "CloneStates"
BINDING_NAME_TOGGLELEADERSTATUS = "Toggle CloneStates Leader Flag"
I'm sure there's better ways to program the above which I'll learn as I go but it seems like I should be able to use if-if-if since all those are discrete incidents. On the subject, can anyone explain the usage of if-then statement around my command to register events? something like:

Code:
if thisIsLeadWindow then
  LeaderMessageHandlerFrame:RegisterEvent("CHAT_MSG_SAY")
end
I didn't get an error but nothing registered. I'm guessing that the RegisterEvent has to happen onload or something else I'm not familiar with

thanks in advance

Last edited by shalom69 : 02-26-13 at 09:13 PM.
  Reply With Quote