tropicdome / MyPetBattle

6 stars 7 forks source link

Don't summon pet if pet team is unchanged #19

Closed joevt closed 11 years ago

joevt commented 11 years ago

Whenever I log in, a pet is summoned and then immediately dismissed. This can be cleaned up a bit. I think the same thing happens if you just click the "Make random team" button (since the team doesn't change randomly yet).

Before setting a pet, check if it's a different pet first:

    local petGUID = C_PetJournal.GetPetLoadOutInfo(1)
    if petID ~= petGUID then
        C_PetJournal.SetPetLoadOutInfo(1, petID) -- Pet slot 1
    end

However, this doesn't work since petGUID is nil at login for some reason. Maybe there's an event that will signal when the information is available? The simplest alternative is to not do anything if it's nil:

    print("|cFF4169E1 Setting team...!")

    local petGUID = C_PetJournal.GetPetLoadOutInfo(1)
    if not petGUID then
        print("|cFFADFF2F Not ready to set team!")
        return
    end

Then have the 1 second timer do the initial setteam call:

MPB_didsetteam = false

local function MPB_onUpdate(self,elapsed)
...
    if MPB_timerOneSec >= 1 then

        if not MPB_didsetteam then
            local desiredPetLevel = EditBox_PetLevel:GetText()  -- Get user input for desired pet level
            MyPetBattle.setTeam(desiredPetLevel)                -- Setup our team
            local petGUID = C_PetJournal.GetPetLoadOutInfo(1)
            if petGUID then
                MPB_didsetteam = true
            end
        end