View Single Post
03-10-13, 05:47 PM   #15
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Originally Posted by shalom69
looking at this code (code isn't important except the highlighted part)

Code:
if (msg == "INCOMBAT FLAGGED") then
    if sender == UnitName("player") then
        local clone, target
        for clone, target in pairs(cloneTargetTable) do
            if target == "NONE" or nil then
                RaidNotice_AddMessage(RaidWarningFrame, clone .." HAS NO TARGET", ChatTypeInfo["RAID_WARNING"])
            end
        end
    elseif not UnitAffectingCombat("player") then
        RaidNotice_AddMessage(RaidWarningFrame, sender .." HAS ENTERED COMBAT", ChatTypeInfo["RAID_WARNING"])			
    end    
end
is there a way to declare the variables one further level in?

for example I know you can do

Code:
local _,target = strsplit(" ", msg, 2)
and declare it right in the operation you're doing. just that quick question,

thanks
You don't need to declare those variables as local at all, because they are automatically defined as local to the scope of the loop when used in a "for" statement:

Code:
for k, v in pairs(t) do
   -- k and v exist here
end
-- but not here
Code:
for i = 1, 10 do
   -- i exists here
end
-- but not here
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote