Thread Tools Display Modes
06-17-20, 10:49 AM   #1
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
Lua logic question

I come from C++ and have coded in that language for a long time. I have a question about a simple if-statement that just won't work.

The variables petGUID and playerGUID exists. The sourceGUID and destGUID are read by CombatLogGetCurrentEventInfo() in a COMBAT_LOG_EVENT_UNFILTERED event. I can't for my life understand how it can write the petGUID when i check it as false?

As i read it the if-statement says that the sourceGUID variable can EITHER be playerGUID or petGUID but the destGUID CANNOT be petGUID or playerGUID. Is there something in lua i have missed? The if-statement still writes destGUID as petGUID. How is that possible?

if (sourceGUID == playerGUID or sourceGUID == petGUID) and (destGUID ~=petGUID and destGUID ~=playerGUID) then
print("sourceGUID "..sourceGUID)
print("destGUID "..destGUID)
end
  Reply With Quote
06-17-20, 11:04 AM   #2
d87
A Chromatic Dragonspawn
 
d87's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 163
Could be actual pet guid changed somewhere along the line since you stored it.

Try doing a fresh UnitGUID("pet") every time or consider using source flags for this check
  Reply With Quote
06-17-20, 11:10 AM   #3
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
Originally Posted by d87 View Post
Could be actual pet guid changed somewhere along the line since you stored it.

Try doing a fresh UnitGUID("pet") every time or consider using source flags for this check
It is checked immediately above, and it's the same GUID as read from the beginning in PLAYER_ENTERING_WORLD. So you can't see any problem with the logic then?
  Reply With Quote
06-17-20, 11:14 AM   #4
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
First of all, the source and destination variables aren't read by CombatLogGetCurrentEventInfo(), they are written by it.

Secondly, could you please share your entire code? Getting assistance with a part of some code doesn't work if you don't share all of it.
  Reply With Quote
06-17-20, 11:14 AM   #5
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
Ah. You are right. I thought the petGUID was unique, and didn't change. I havent changed pet, it's the same all the time, but still it gives it new GUID during a session. Is that normal?
  Reply With Quote
06-17-20, 11:18 AM   #6
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
Originally Posted by Kanegasi View Post
First of all, the source and destination variables aren't read by CombatLogGetCurrentEventInfo(), they are written by it.

Secondly, could you please share your entire code? Getting assistance with a part of some code doesn't work if you don't share all of it.
local function DummyFrame_OnEvent(self, event, ...)


if event == "PLAYER_ENTERING_WORLD" then

playerGUID = UnitGUID("player")
if UnitGUID("pet") ~= nil then
petGUID = UnitGUID("pet")
end
DummyFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")


elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then

local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()


if (sourceGUID == playerGUID or sourceGUID == petGUID) and (destGUID ~=petGUID and destGUID ~=playerGUID) then
print("sourceGUID "..sourceGUID)
print("destGUID "..destGUID)
print(timestamp.."|n")
end



end
DummyFrame:SetScript("OnEvent", DummyFrame_OnEvent)
  Reply With Quote
06-17-20, 11:24 AM   #7
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
I could just extract "pet" from the GUID and check that and it will solve the problem. This is happening when i am flying with a mount from flight master. As soon as i land it will write the code inside the if-statement. And now when i check the pet GUID has changed. Like i said i thought it was unique during a session.
  Reply With Quote
06-17-20, 11:30 AM   #8
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
This is very interersting. MAybe you knew this, but i did'nt. When i land, flying with the flight master the pet GUID changes like this:

petGUID from start: 1801D465A0

When landing at flight master: 1901D465A0

Flying again and landing at flight master: 1A01D465A0

d87, you were right.
  Reply With Quote
06-17-20, 11:40 AM   #9
Kanegasi
A Molten Giant
 
Kanegasi's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2007
Posts: 666
All player GUIDs are unique and do not change as long as the character does not change faction or realm. I'm pretty sure they stick if you only name change, but I could be wrong.

All other GUIDs are designated on spawn. Every single object, item, npc, anything else in the game receives a unique GUID upon spawn, including your pet, since it's a controllable npc. When your pet disappears, it will get a new GUID when you see it again.

Use the event UNIT_PET with the first arg being "player" to get the new GUID each time.

Also, you were missing an end, you need to make playerGUID and petGUID a local to prevent other addons from changing them, and the entering world event has login and reload boolean payloads so you don't have to unregister that event.

Lua Code:
  1. local playerGUID, petGUID
  2. local function DummyFrame_OnEvent(self, event, ...)
  3.     if event == "PLAYER_ENTERING_WORLD" then
  4.         local login, reload = ...
  5.         if login or reload then
  6.             playerGUID = UnitGUID("player")
  7.             petGUID = UnitGUID("pet")
  8.         end
  9.     elseif event == "UNIT_PET" then
  10.         local unit = ...
  11.         if unit == "player" then
  12.             petGUID = UnitGUID("pet")
  13.         end
  14.     elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
  15.         local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
  16.         if (sourceGUID == playerGUID or sourceGUID == petGUID) and (destGUID ~= petGUID) and (destGUID ~= playerGUID) then
  17.             print("sourceGUID "..sourceGUID)
  18.             print("destGUID "..destGUID)
  19.             print(timestamp.."|n")
  20.         end
  21.     end
  22. end
  23. DummyFrame:SetScript("OnEvent", DummyFrame_OnEvent)
  Reply With Quote
06-17-20, 11:49 AM   #10
millo666
A Murloc Raider
Join Date: Jun 2020
Posts: 7
Originally Posted by Kanegasi View Post
All player GUIDs are unique and do not change as long as the character does not change faction or realm. I'm pretty sure they stick if you only name change, but I could be wrong.

All other GUIDs are designated on spawn. Every single object, item, npc, anything else in the game receives a unique GUID upon spawn, including your pet, since it's a controllable npc. When your pet disappears, it will get a new GUID when you see it again.

Use the event UNIT_PET with the first arg being "player" to get the new GUID each time.

Also, you were missing an end, you need to make playerGUID and petGUID a local to prevent other addons from changing them, and the entering world event has login and reload boolean payloads so you don't have to unregister that event.

Lua Code:
  1. local playerGUID, petGUID
  2. local function DummyFrame_OnEvent(self, event, ...)
  3.     if event == "PLAYER_ENTERING_WORLD" then
  4.         local login, reload = ...
  5.         if login or reload then
  6.             playerGUID = UnitGUID("player")
  7.             petGUID = UnitGUID("pet")
  8.         end
  9.     elseif event == "UNIT_PET" then
  10.         local unit = ...
  11.         if unit == "player" then
  12.             petGUID = UnitGUID("pet")
  13.         end
  14.     elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
  15.         local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()
  16.         if (sourceGUID == playerGUID or sourceGUID == petGUID) and (destGUID ~= petGUID) and (destGUID ~= playerGUID) then
  17.             print("sourceGUID "..sourceGUID)
  18.             print("destGUID "..destGUID)
  19.             print(timestamp.."|n")
  20.         end
  21.     end
  22. end
  23. DummyFrame:SetScript("OnEvent", DummyFrame_OnEvent)
Yeah i missed to copy that end-statement, i had it. I have the locals above, but forgot to dump the code. I had a lot of comments in the code and did'nt want to share that, and missed the end and the locals. Sorry.
This is what i had.



local playerGUID
local petGUID
local function DummyFrame_OnEvent(self, event, ...)


if event == "PLAYER_ENTERING_WORLD" then

playerGUID = UnitGUID("player")
print(playerGUID)
print(petGUID)
DummyFrame:UnregisterEvent("PLAYER_ENTERING_WORLD")


elseif event == "COMBAT_LOG_EVENT_UNFILTERED" then
petGUID = UnitGUID("pet")
local timestamp, subevent, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags = CombatLogGetCurrentEventInfo()

if (sourceGUID == playerGUID or sourceGUID == petGUID) and (destGUID ~=petGUID) and (destGUID ~=playerGUID) then
print("sourceGUID "..sourceGUID)
print("destGUID "..destGUID)
print(timestamp.."|n")
end

end

end
DummyFrame:SetScript("OnEvent", DummyFrame_OnEvent)

Thank you very much for your help, both of you.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Lua logic question

Thread Tools
Display Modes

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