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 |
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 |
Quote:
|
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. |
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?
|
Quote:
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) |
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.
|
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. |
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:
|
Quote:
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 04:00 AM. |
vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI