WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Can Anyone Explain This Mystery? (https://www.wowinterface.com/forums/showthread.php?t=57071)

fakesaint41 03-19-19 12:27 PM

Can Anyone Explain This Mystery?
 
I'm stumped... I've worked around it but I'd like to know why it happens. Calling C_PetJournal.GetNumPets() in the handler for the PLAYER_LOGIN or PLAYER_ENTERING_WORLD returns 0... but sticking the call at the beginning of the addon works just fine.


Code:

local numPets = C_PetJournal.GetNumPets()
print("File Start: "..numPets)

function AddonFrame:PlayerLoginHandler()
    local numPets = C_PetJournal.GetNumPets()
    print("Login: "..numPets
end

--  Output in Chat Window on Reload:
--
--  File Start: 1002
--  Login: 0



Subsequent calls after login are back to normal. I'm confused why it wouldn't work in the PLAYER_LOGIN handler, despite the API being available before.

I'll give 1 or 2 helpful geniuses here any of the new Raiding With Leashes Pets if you can solve this mystery!! :banana:

ArsenalLagspike 03-19-19 03:56 PM

Need to see more code. I have a couple of assumptions, but without code I can't know for sure.

Is the AddomFrame handler that you defined being called from the XML template? Or somewhere else in Lua?

kurapica.igas 03-19-19 07:58 PM

You'd better try the PET_JOURNAL_LIST_UPDATE event to start using the pet data

elcius 03-19-19 11:16 PM

most api functions that provide data about the character or account will return data from the previously logged in character if called before PLAYER_LOGIN.
If you close the game you'll probably find it returns 0 both times.

fakesaint41 03-20-19 05:06 PM

Quote:

Originally Posted by elcius (Post 331737)
most api functions that provide data about the character or account will return data from the previously logged in character if called before PLAYER_LOGIN.
If you close the game you'll probably find it returns 0 both times.

Mystery Solved!! That's exactly what was fooling me. If you like, PM me name/server and what pet you want!
:D


All times are GMT -6. The time now is 01:37 AM.

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