You can just call
button:SetAttribute() again when you need to update it. This can't be done during combat however.
For example:
Lua Code:
local button=CreateFrame("Button",nil,aura_env.region,"SecureActionButtonTemplate");
button:RegisterForClicks("LeftButtonUp","RightButtonUp");
button:SetAllPoints(aura_env.region);
button:SetAttribute("*type1","target");
button:SetAttribute("*type2","focus");
button:SetAttribute("unit","none");-- Special UnitID for "no unit"
button:RegisterEvent("PLAYER_ROLES_ASSIGNED");
button:RegisterEvent("GROUP_ROSTER_UPDATE");
button:RegisterEvent("RAID_ROSTER_UPDATE");
button:RegisterEvent("PLAYER_REGEN_ENABLED");
button:SetScript("OnEvent",function(self)
if not InCombatLockdown() then-- Can't update in combat
local unit="none";
if IsInRaid() then
for i=1,MAX_RAID_MEMBERS do
local raidunit="raid"..i;
local raidid=UnitInRaid(raidunit);-- Unit-to-ID mappings aren't guaranteed
if raidid and not UnitIsUnit(raidunit,"player") and (select(10,GetRaidRosterInfo(raidid))=="maintank" or UnitGroupRolesAssigned(raidunit)=="TANK") then
unit=raidunit; break;
end
end
end
self:SetAttribute("unit",unit);
end
end);