DengSir / tdBattlePetScript_Rematch

7 stars 4 forks source link

LUA error on mouseover #4

Open Hemario opened 5 years ago

Hemario commented 5 years ago

LUA error occurs when mousing over the script selector on the top of the window duting a pet battle.

30x tdBattlePetScript_Rematch\Addon.lua:40: Usage: GetPetInfoByID(petGUID) C: in function GetPetInfoByPetID' tdBattlePetScript_Rematch\Addon.lua:40: in functionGetPetTip' tdBattlePetScript_Rematch\Addon.lua:59: in function tipFormatting' tdBattlePetScript\UI\UI.lua:31: in functionOpenPluginTooltip' tdBattlePetScript\UI\PetBattle.lua:186: in function <tdBattlePetScript\UI\PetBattle.lua:178> (tail call): ?

(tail call): ? ...PetScript\Libs\tdGUI\Libs\LibClass-2.0-7\Class-2.0.lua:156: in function Fire' ...Ons\tdBattlePetScript\Libs\tdGUI\Widget\ViewItem.lua:28: in functionFireHandler' ...Ons\tdBattlePetScript\Libs\tdGUI\Widget\ViewItem.lua:59: in function <...Ons\tdBattlePetScript\Libs\tdGUI\Widget\ViewItem.lua:57>

bloerwald commented 3 years ago

This issue comes from the team having set a random pet in Rematch.

 function Addon:GetPetTip(id)
     if not id then
         return ' '
     end
+    if id:find('random:') == 1 then
+        return 'A random pet'
+    end
     local _, customName, _, _, _, _, _, name, icon, petType = C_PetJournal.GetPetInfoByPetID(id)
     if not name then
         return ' '
     end
     local health, maxHealth, power, speed, rarity = C_PetJournal.GetPetStats(id) 

     return format('|T%s:20|t %s%s|r', icon, ITEM_QUALITY_COLORS[rarity-1].hex, customName or name)
 end

will fix/avoid it.

fubaWoW commented 1 year ago

this will not fix "ignored" pets and error is still present!

Better way to fix this is just to replace if not id then with if (not id) or (not string.find(id, "BattlePet.*")) then so ANY non Pet-GUID will be ignored

Complete Function:

function Addon:GetPetTip(id)
    if (not id) or (not string.find(id, "BattlePet.*")) then
        return ' '
    end
    local _, customName, _, _, _, _, _, name, icon, petType = C_PetJournal.GetPetInfoByPetID(id)
    if not name then
        return ' '
    end
    local health, maxHealth, power, speed, rarity = C_PetJournal.GetPetStats(id)

    return format('|T%s:20|t %s%s|r', icon, ITEM_QUALITY_COLORS[rarity-1].hex, customName or name)
end
axc450 commented 1 year ago

I have a fix for this that uses the proper Rematch API for fetching pet data instead of trying to do it using the Blizz APIs in this file.