Greetings:
I am working on a small data export mod to dump out all the information on my Battle Pets. For the most part, the code is working just fine, but I think the problem I am having has to do with timing. It seems like the complete Battle Pet info isn't fully ready by the time the Player events are fired. Here is the function that is handling the pet info.
Code:
function CBPetList_GetBattlePets()
local numPets, numOwned = C_PetJournal.GetNumPets(false)
CBPetCount = numOwned
for iLoop = 1, numPets do
local petID, speciesID, owned, customName, level, favorite, isRevoked, speciesName, icon, petType, companionID, tooltip, description, isWild, canBattle, isTradeable, isUnique = C_PetJournal.GetPetInfoByIndex(iLoop, false)
local health, maxHealth, power, speed, rarity = C_PetJournal.GetPetStats(petID)
local isFavorite = C_PetJournal.PetIsFavorite(petID)
if owned then
if CBPetListTable[speciesID] == nil then
CBPetListTable[speciesID] = {}
end
CBPetListTable[speciesID]["name"] = speciesName
CBPetListTable[speciesID]["customName"] = customName
CBPetListTable[speciesID]["favorite"] = isFavorite
CBPetListTable[speciesID]["rarity"] = rarity
CBPetListTable[speciesID]["level"] = level
CBPetListTable[speciesID]["maxHealth"] = maxHealth
CBPetListTable[speciesID]["power"] = power
CBPetListTable[speciesID]["speed"] = speed
end
end
end
CBPetCount and CBPetListTable are Saved Variables.
I have a slash command that can manually run this function. I have the following events registered and each of the COMPANION_/PLAYER_ events call the above function.
Code:
CBPetList:RegisterEvent("ADDON_LOADED")
CBPetList:RegisterEvent("COMPANION_LEARNED")
CBPetList:RegisterEvent("PLAYER_ENTERING_WORLD")
CBPetList:RegisterEvent("PLAYER_ALIVE")
If I issue my "/petlist count" command right after getting into the game, it usually prints out 0 (it once said the proper count, but never again). This would be showing the Battle Pet count from the above events.
If I run "/petlist update" it spits out the proper Battle Pet count.
My question is, is there some better event I should be using like (joke) "PLAYER_DATA_FINALLY_LOADED" or is there some way to delay-fire the calling of that function? Or is there some other fundamental mistake I am making?
CB