I guess "auto_saying" is either true or false, so why not just:
if auto_saying then X else Y end
If you have two types of auto_saying (where 0 or nil is off) then:
if auto_saying == 1 then X elseif auto_saying == 2 then Y end
In this version you have a 'local auto_saying' = 1 or 2 would trigger X or Y, any other value is skipped
"1" and 1 are different things, one is string and the other is number. Also a tip, instead of using 0/1 as true/false simply use "nil" for false and 1 for true, reason is that "nil" is nothing while "0" is a integer and eats more on the performance.
Code:
aherolust:SetScript("OnEvent", function(self, event, _, etype, ...)
if event == "COMBAT_LOG_EVENT_UNFILTERED" and etype == "SPELL_AURA_APPLIED" then
if not autoHERO then return end
local myGUID = UnitGUID("player")
local _, _, _, srcName, _, _ = select(1, ...)
local _, spellName = select(7, ...)
if not myGUID == srcName then return end
if spellName == GetSpellInfo(61295) then -- Riptide (Rank 1), rank does not really matter as the name is what we are after here!
if auto_saying == 1 then
SendChatMessage("Value is (1): "..auto_saying, "SAY")
elseif auto_saying == 2 then
SendChatMessage("Value is (2): "..auto_saying, "SAY")
end
end
end
end)
Few notes, I would perhaps use "self" to store temp values but recently I've noticed that performance is not as good when querying tables too often. Other thing you could do is declare all the variables you will ever use in the main addon file itself using "local" and followed by all the variables, separated by comma. This way you don't create a new variable each time a spell cast is successful, but rather use the old temporary variable memory space -it's more efficient and CPU friendly.
local a, b, c, d = 2, 1 -- here a=2 and b=1 while the rest are "nil"
f:SetScript("OnUpdate", function(self, elapsed)
c = (c or 0) + elapsed -- (c or 0) will either be the value of c or if it's the first run it's nil so then it uses 0, then it adds the elapsed time since last call. this is a basic counter but more efficient than for example:
end)
myGlobalVar = 0
f:SetScript("OnUpdate", function(self, elapsed)
local time = elapsed -- each run this "time" would be added in the RAM then deleted, instead of just overwritten, it's a silly example tough as you never would need to do this, normally you would just myGlobalVar = myGlobalVar + elapsed straight away. :P
myGlobalVar = myGlobalVar + time
end)
One thing I am not too sure about, I notice some use:
function(self, ...)
var = select(2, ...)
end
While I would simply use "arg2" to refer to the 2nd argument in the "...", it works but not sure if it's more efficient or a old way to do this. Hmm....