prior to this last patch, there was some part of the battle frame during a pet battle that supplied both a playerIndex value and a petIndex value. Those along with the predefined constants for ally and opponent were removed. Anyone know what the replacement is? Trying to fix up derangements pet battle cooldowns, but don’t know what to replace those with.
I was able to just manually redefine the constants, but not sure how to get the index values so the addon can process which side and which pet is doing what.
LE_BATTLE_PET_ALLY is now Enum.BattlePetOwner.Ally
LE_BATTLE_PET_ENEMY is now Enum.BattlePetOwner.Enemy
I’m not sure what you mean by index values. PetBattleFrame.ActiveAlly and PetBattleFrame.ActiveEnemy are the frames at the top of the battle UI for each side.
1 Like
Thank you about the constants! I’ll update them in my code
Sorry, I"m not familiar with the right terms / names. I was speaking off the cuff there at the end.
Derangements has code that is failing on playerIndex and petIndex like:
local petFrame = self:GetParent():GetParent();
local hp = C_PetBattles.GetHealth(petFrame.playerIndex, petFrame.petIndex);
and
local petFrame = self:GetParent():GetParent();
local opposingTeam = LE_BATTLE_PET_ALLY + LE_BATTLE_PET_ENEMY - petFrame.playerIndex; --the OTHER player
local opposingPetSlot = C_PetBattles.GetActivePet(opposingTeam);
local opposingType = C_PetBattles.GetPetType(opposingTeam, opposingPetSlot);
both of those are failing due to .playerIndex and/or .petIndex
In that lower one, they seem to be doing some math based on an index value to decide whether the index is for the right side or left side (I’m guessing cause pet pvp can put you on either side???)
The .playerIndex and .petIndex values seem to be the broken now as it says they don’t exist anymore. I’m hoping someone knows what they became as well?
Sorry about all the confusion!
Maybe a side question, what online resources do we have to find the stuff like the change to Enum.BattlePetOwner.Ally and Enum.BattlePetOwner.Enemy. Didn’t find them in wowpedia’s api list. Tried looking at the api at tomrus, but none of the recent commit history has any changes to LE_BATTLE_PET_ALLY for example (unless maybe Tomrus is ahead of the changes?). I can try to dig around for he playerIndex, petIndex stuff if I just know the genral place to look
I look at the default code:
The battle UI is in Interface\AddOns\Blizzard_PetBattleUI.
I opened up a 9.2 version of the lua/xml and across all files saw no reference to playerIndex that would relate to pet battles, so I’m thinking Deranged may have assigned those to the frames for its own purposes. petIndex is used a lot in the battle ui but not as a frame property that I saw in a quick scan.
If you don’t already, I highly recommend getting an editor that can search for terms across multiple files, like Visual Studio Code or NotePad++. Then it takes seconds to search for where Blizzard uses a term or API and see how they use it.
In the 10.0.2 code I noticed LE_BATTLE_PET_ALLY was missing. For this you could search for C_PetBattles and you’ll see references like
local numOpponentPets = C_PetBattles.GetNumPets(Enum.BattlePetOwner.Enemy);
If you had the 9.2.7 code (I believe those websites allow you to download it, I’m not sure), you would see this in Deprecated_9_1_0.lua:
-- Pet battle enum conversions
do
LE_BATTLE_PET_WEATHER = Enum.BattlePetOwner.Weather;
LE_BATTLE_PET_ALLY = Enum.BattlePetOwner.Ally;
LE_BATTLE_PET_ENEMY = Enum.BattlePetOwner.Enemy;
(So these enums worked in 9.1.0 it looks like, but I didn’t know about them until stuff started to break!)
2 Likes
Ok thanks!
On the player index thing:
Prior to this last patch, Derangements had no lua errors, then patch hit and it started having errors about playerIndex with no changes to the addon code. That’s why I was surprised when it stopped working. So i feel like something removed it from somewhere with this patch. I just can’t figure out what.
EDIT: I traced it down I think. But haven’t figured out why yet. I think playerIndex is created here:
DeePetBattlePet_OnLoad = function( self, playerIndex, frameIndex )
--remember which pet we're watching
self.playerIndex = playerIndex;
self.frameIndex = frameIndex;
print("In OnLoad");
I put a print statement in there and that function is called 6 times at login.
I then put a print statement in one of the offending sections:
updateAbilityButtonBetterIcon = function(self)
self.BetterIcon:Hide();
self.BetterIcon2:Hide();
local petFrame = self:GetParent():GetParent();
print("In updateAbilityButton_BetterIdon");
local opposingTeam = LE_BATTLE_PET_ALLY + LE_BATTLE_PET_ENEMY - petFrame.playerIndex; --the OTHER player
local opposingPetSlot = C_PetBattles.GetActivePet(opposingTeam);
local opposingType = C_PetBattles.GetPetType(opposingTeam, opposingPetSlot);
Which is called many more times than just 6. So I am guessing this is getting called for some set of UI elements and the On_Load for specific ones isn’t happening before this code does. So my guess is something happened to when OnLoad is called in this patch, either because of timing or a change in the registration process (I remember somethings like tooltips changed their hooks, but no errors here on that yet) .
I’m guessing the addon expected OnLoad to be called as the petbattle UI loaded for a battle (which is when the LUA error occurs)
Found by searching for “.playerIndex =”, in DeePetBattlePet_OnLoad:
DeePetBattlePet_OnLoad = function( self, playerIndex, frameIndex )
--remember which pet we're watching
self.playerIndex = playerIndex;
self.frameIndex = frameIndex;
This onload is in DeePetBattlePetTemplate, inherited by DeePetBattleAllyPetTemplate and DeePetBattleEnemyPetTemplate, which are inherited by the following with this in their Onloads:
DeePetBattleFrame.Ally1: DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ALLY, 1);
DeePetBattleFrame.Ally2: DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ALLY, 2);
DeePetBattleFrame.Ally3: DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ALLY, 3);
DeePetBattleFrame.Enemy1: DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ENEMY, 1);
DeePetBattleFrame.Enemy2: DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ENEMY, 2);
DeePetBattleFrame.Enemy3: DeePetBattlePet_OnLoad(self, LE_BATTLE_PET_ENEMY, 3);
You can probably update those six OnLoads to use the enum instead of the LE_BATTLE to fix the playerIndex bit.
1 Like
If you want an online source for it.
1 Like
On this bit:
local opposingTeam = LE_BATTLE_PET_ALLY + LE_BATTLE_PET_ENEMY - petFrame.playerIndex; --the OTHER player
This is just a clever way to use go back and forth between ally/enemy.
Enum.BattlePetOwner.Ally = 1
Enum.BattlePetOwner.Enemy = 2
If frame is Ally: 1+2-1 = 2, Enemy
If frame is Enemy: 1+2-2 = 1, Ally
In a best-practice sense it’s a little shaky, since if they decide to make Enum.BattlePetOwner.Ally equal 0x001238E one day, then stuff breaks hard.
Thank you Gello! That fixed it. I would never have found that. I was looking in the LUA file the whole time. Didn’t realize you could call API enums from the XML as well, so I didn’t check there.
I can replace that math with a regular logical switch. The weird part is if the value is Enum.BattlePetOwner.Weather
which has a value of 0, then the result would be 3. So I am assuming that this never gets called with Weather as the value or that the value caps at max somehow in the function calls
I’m super sorry about taking your time like that.
I’m glad you got it working, it was no problem! I enjoy tinkering with this stuff and I have an affinity for battle pet-related code.
1 Like