Thread Tools Display Modes
08-10-10, 03:26 PM   #1
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Event and SendChatMessage problems.. /facepalm

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 == "Riptide" then
          <<<INSERT HERE>>>
     end
  end
end)
^ works fine

Now when I add this where it says <<<INSERT HERE>>>

Code:
	if (auto_saying == "2") then 
	   SendChatMessage("2? : "..auto_saying, "SAY", nil, nil); 
	elseif (auto_saying == "3") then 
	   SendChatMessage("3? : "..auto_saying, "SAY", nil, nil); 
	end
It stops working.

auto_saying is equal to 3 as declared earlier in the file.

Any help would be appreciated because I'm running out of ideas.
  Reply With Quote
08-11-10, 08:24 PM   #2
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Is it "3" (a string) or 3 (a number)?
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-12-10, 07:27 AM   #3
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
The number 3 is a number.

You got me to thinking about that so I just tried a work around and what do you know, it works. Thanks a bunch, lol. :P

I change my previous if statements to:
Code:
	if (auto_saying > 1 and auto_saying < 3) then 
	   SendChatMessage("2? : "..auto_saying, "SAY", nil, nil); 
	elseif (auto_saying > 2 and auto_saying < 4") then 
	   SendChatMessage("3? : "..auto_saying, "SAY", nil, nil); 
	end
Works exactly like it should. Now off to put in the actual chatmessage bs and update my mod.
  Reply With Quote
08-15-10, 06:46 PM   #4
Vlad
A Molten Giant
 
Vlad's Avatar
AddOn Author - Click to view addons
Join Date: Dec 2005
Posts: 793
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....

Last edited by Vlad : 08-15-10 at 06:52 PM.
  Reply With Quote
08-15-10, 08:50 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Originally Posted by Naberius View Post
The number 3 is a number.

You got me to thinking about that so I just tried a work around and what do you know, it works. Thanks a bunch, lol. :P

I change my previous if statements to:
Code:
	if (auto_saying > 1 and auto_saying < 3) then 
	   SendChatMessage("2? : "..auto_saying, "SAY", nil, nil); 
	elseif (auto_saying > 2 and auto_saying < 4") then 
	   SendChatMessage("3? : "..auto_saying, "SAY", nil, nil); 
	end
Works exactly like it should. Now off to put in the actual chatmessage bs and update my mod.
Close.
Code:
	if auto_saying == 2 then 
	   SendChatMessage("2? : "..auto_saying, "SAY", nil, nil); 
	elseif auto_saying == 3 then 
	   SendChatMessage("3? : "..auto_saying, "SAY", nil, nil); 
	end
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
08-16-10, 05:38 PM   #6
Tim
A Rage Talon Dragon Guard
 
Tim's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 309
Originally Posted by Vladinator View Post
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.
In my original post I stated that auto_saying was equal to 3 thus making it not a true/false statement. I was running into the problem where I was treating the number 3 as a string not a number thus causing issues, all is remedied now though. :P

Seerah, yeah that would work as well. I was tired when trying to code this so I couldn't think straight. I'm going to leave it how I have it as it works the same and "if it ain't broke don't fix it". :P
  Reply With Quote
08-16-10, 09:07 PM   #7
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Yes, it works, but why do twice as much work? (two comparison checks as opposed to one)
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Event and SendChatMessage problems.. /facepalm


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