I've written an addon to move/show/hide various parts of my UI based on if I'm in a party or not, however my Unit Frames (Pitbull) are not created right away when it is loaded, however my addon tries to modify it right when its loaded, so it tries to modify the frame thats not yet created. Is there a way I can make a delay of about 2 seconds on the execution of my code?
Code:
function MiKE_OnEvent()
local raidNum = GetNumRaidMembers();
local partyNum = GetNumPartyMembers();
if raidNum < 0 or partyNum < 0 then
DEFAULT_CHAT_FRAME:AddMessage("Somthing is seriously wrong, you have "..raidNum.." members in your raid and "..partyNum.." members in your party. These numbers should be >= 0");
elseif raidNum == 0 and partyNum == 0 then
MiKE_NotParty();
else
-- I want the in party setup to be the fallback, it works for solo and party, just not ideal for solo (imo).
MiKE_Party();
end
end
function MiKE_NotParty()
-- We are not in a party, we want to flatten discord to two rows and move it down to the bottom of the screen (where the party normally is)
DAB_Settings["done"].Bar[5].rows = 2 -- Change the variable for rows.
DAB_Bar_Initialize(5); -- Re-initialize the bar using DAB's built in function.
DAB_ActionBar_5:ClearAllPoints(); -- Clear the points so the bar isn't bound to anything.
DAB_ActionBar_5:SetPoint("CENTER", "UIParent", "CENTER", 0, -380); -- Bind the bar to the point where the party normally is.
OmenAnchor:Hide(); -- Omen isn't needed solo, hide it.
MinimapCluster:ClearAllPoints(); -- Clear points the minimap is bound to
MinimapCluster:SetPoint("CENTER", "UIParent", "CENTER", 252, -352); -- Bind the minimap to a new points (RMM remembers position by character, and I don't want to set it up on all 6)
MinimapCluster:Show(); -- Show the minimap, you don't need the minimap in an instance.
PitBullUnitFrame1:ClearAllPoints(); -- Clear points the bar is bound to.
PitBullUnitFrame1:SetPoint("CENTER", "UIParent", "CENTER", -93, -300); -- Set a new point for the player frame to go to.
ChatFrame1:SetWidth(340); -- We can extend the chat box now since the party frames aren't in the way.
end
function MiKE_Party()
-- We are in a party, we want to condense discord to four rows and move it up a bit (so its not in the way of the party frames).
DAB_Settings["done"].Bar[5].rows = 4 -- Change the variable for rows.
DAB_Bar_Initialize(5); -- Re-initialize the bar using DAB's built in function.
DAB_ActionBar_5:ClearAllPoints(); -- Clear the points so the bar isn't bound to anything.
DAB_ActionBar_5:SetPoint("CENTER", "UIParent", "CENTER", 0, -271); -- Bind the bar to the point where the party normally is.
OmenAnchor:Show(); -- Omen is generally useful in a party, show it.
MinimapCluster:Hide(); -- Generally don't need minimap in instance (also in same spot as Omen).
PitBullUnitFrame1:ClearAllPoints(); -- Clear points the player frame is bound to, so we can move it where it doesn't interfere.
PitBullUnitFrame1:SetPoint("CENTER", "UIParent", "CENTER", -93, -160); -- Set the new point for the player frame.
ChatFrame1:SetWidth(285); -- Party frames in the way, chat has to be shortened.
end
local MiKE = CreateFrame("frame");
MiKE:SetScript("OnEvent", MiKE_OnEvent);
MiKE:SetScript("OnLoad", MiKE_OnEvent); -- this is the part that needs the delay.
MiKE:RegisterEvent("PARTY_MEMBERS_CHANGED");