Thread Tools Display Modes
Prev Previous Post   Next Post Next
09-13-23, 03:09 PM   #1
minstril43
A Kobold Labourer
Join Date: Sep 2023
Posts: 1
Macro button problem

Hi.

Until today I was having no problems with the following button code:

Code:
local buttonBattlePetHeal = CreateFrame('button', 'BattlePetHeal', nil, 'SecureActionButtonTemplate')
buttonBattlePetHeal:SetAttribute('type', 'macro')
buttonBattlePetHeal:SetScript('PreClick', function(self)

    -- check if the character is in combat
    if InCombatLockdown() then
        -- character is in combat, end the function
        self:SetAttribute('macrotext', '')
        return
    -- else - character isn't in combat, do nothing
    end
    
    -- check if any pet in the currently loaded team is injured

    local petID, petHealth, petMaxHealth = 0
    local petInjured = false

    for i = 1, 3 do
        -- get Id for current pet
        petID = C_PetJournal.GetPetLoadOutInfo(i)
        if (petID ~= 0) then
            -- pet has an ID, check if it is injured (health < maxHealth)
            petHealth, petMaxHealth = C_PetJournal.GetPetStats(petID)
            if petHealth < petMaxHealth then
                -- pet is injured, set injured flag to true and stop the loop
                petInjured = true
                break
            -- else - pet is not injured, do nothing and continue the loop
            end
        -- else - no petID found, do nothing and continue the loop
        end
        -- reset pet attriibutres and continue the loop
        petID, petHealth, petMaxHealth = 0
    end

    -- if no pets are injured, print a message letting the player know and end the function

    -- check if the injured flag is still false
    if not petInjured then
        -- print a message telling the player that all pets in the team are at full health
        DEFAULT_CHAT_FRAME:AddMessage('All pets in the team are at full health.', 1, 1, 0)
        -- end the function
        self:SetAttribute('macrotext', '')
        return
    end
    
    -- at this point at least one pet in the current team is injured

    -- if Revive Battle Pets is off cooldown then cast it.
    -- otherwise, if a Battle Pet Bandage is available then use it.

    -- check if Revive Battle Pets is off cooldown
    if (GetSpellCooldown(125439) == 0) then
        -- Revive Battle Pets is off cooldown, cast it
        self:SetAttribute('macrotext', '/use Revive Battle Pets')
        return
    else
        -- Revive Battle Pets is on cooldown, check if any Battle Pet Bandages are available
        if (GetItemCount(86143) ~= 0) then
            -- a Battle Pet Bandage is available, use it
            self:SetAttribute('macrotext', '/use item:86143')
            return
        else
            -- Battle Pet Bandages are not available, print a message telling the player that
            DEFAULT_CHAT_FRAME:AddMessage('You have no Battle Pet Bandages!', 1, 1, 0)
            -- end the function
            self:SetAttribute('macrotext', '')
            return
        end
    end

    -- end the function
    self:SetAttribute('macrotext', '')
    return

end)
I created a macro in WoW to "/click BattlePetHeal" and, when it was working, it would, if there was a injured pet in the current team, use the Revive Battle Pets spell (if it wasn't on cooldown) or a Battle Pet Bandage instead.

Today, however, when I click the macro button, nothing happens. I've used DEFAULT_CHAT_FRAME:AddMessage messages to confirm the code is running correctly. It's like the "self:SetAttribute('macrotext', '/use Revive Battle Pets')" and "self:SetAttribute('macrotext', '/use item:86143')" aren't working or the 'macrotext' is being reset to ''.

I've confirmed the two macrotexts work in game.

I'm totally confused. :I

Any help appreciated. Thanks in advance.

Last edited by minstril43 : 09-13-23 at 03:38 PM.
  Reply With Quote
 

WoWInterface » Developer Discussions » Lua/XML Help » Macro button problem

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off