Q: Using "x ~= y" correctly

The code below is supposed to filter out combat events that do originate with, or target, the player or the player’s pet. But, it doesn’t work. When I execute this code against target dummies in the presence of other players also attacking the dummies (any dummy), their combat events are getting through.

NOTE: The playerName is the name is the name of my character.

        local stats = {CombatLogGetCurrentEventInfo()}
        local sourceName = stats[EVENT_SOURCENAME]
        local destName   = stats[EVENT_DESTNAME]
        
        if sourceName   ~= playerName and
           sourceName   ~= playersPet and
           destName     ~= playerName and
           destName     ~= playersPet then
           return
        end

Am I missing something? Do I have the conditional expression correct?

Thanks, in advance

Too many ands, not enough ors…

if not (sourceName == playerName or sourceName == playersPet) or not (destName == playerName or destName == playersPet) then 
	return
end

This is not how you access a table with indices, if you want to do it this way you would do it like so

local function OnEvent(self, event)
	local stats = {CombatLogGetCurrentEventInfo()}
	local sourceName = stats[5]
	local destName   = stats[9]
	print(sourceName, destName)
end

local f = CreateFrame("Frame")
f:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
f:SetScript("OnEvent", OnEvent)

See https://wow.gamepedia.com/COMBAT_LOG_EVENT#Examples

Unless for some crazy reason you did

EVENT_SOURCENAME = 5
EVENT_DESTNAME = 9

Thanks Fizzlemizz. I was able to get it work by changing the first “or not” to “and not”…

Cheers,

theres nothing wrong with doing it that way - we obviouisly havent been given all the code, there must be assignments somewhere for that snippet to even work

its hardly crazy to make local constants for blizzard values - if anything its a pretty good habit to get into for wow code. it means when blizzard changes things around (which they tend to do) you only have to change them in one place and your mod is back to working.

blizzard also have the habit of making some constants local to the internal mod where they are used so you have no access to them unless you create equivalent constants in your own mod.

1 Like