|
09-13-23, 03:09 PM | #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) 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. |
|
WoWInterface » Developer Discussions » Lua/XML Help » Macro button problem |
«
Previous Thread
|
Next Thread
»
|
Display Modes |
Switch to Linear Mode |
Hybrid Mode |
Switch to Threaded Mode |
|
|