WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Lua logic question (https://www.wowinterface.com/forums/showthread.php?t=58056)

millo666 06-17-20 10:49 AM

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

d87 06-17-20 11:04 AM

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

millo666 06-17-20 11:10 AM

Quote:

Originally Posted by d87 (Post 336163)
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?

Kanegasi 06-17-20 11:14 AM

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.

millo666 06-17-20 11:14 AM

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?

millo666 06-17-20 11:18 AM

Quote:

Originally Posted by Kanegasi (Post 336165)
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)

millo666 06-17-20 11:24 AM

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.

millo666 06-17-20 11:30 AM

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.

Kanegasi 06-17-20 11:40 AM

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)

millo666 06-17-20 11:49 AM

Quote:

Originally Posted by Kanegasi (Post 336170)
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.


All times are GMT -6. The time now is 01:40 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI