Thread Tools Display Modes
09-21-07, 02:17 PM   #1
MiKE41
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 4
OnLoad delay

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");
  Reply With Quote
09-21-07, 03:12 PM   #2
Kaomie
A Scalebane Royal Guard
 
Kaomie's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 438
Just out of curiosity, did you put Pitbull in the ##Dependencies of your addon TOC?
__________________
Kaomie
"WE LOTS OF PEOPLE FROM STRONG SERVER GUILDS" - Trade Channel
  Reply With Quote
09-21-07, 04:55 PM   #3
MiKE41
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 4
Originally Posted by Kaomie
Just out of curiosity, did you put Pitbull in the ##Dependencies of your addon TOC?
No. I did not.

Code:
## Interface: 20100
## Author: MiKE
## Title: MiKE
## Notes: Changes interface based on group status.
## SavedVariables: 
MiKE.lua
Edit: Just tried it, doesn't change anything at all. Thanks for the idea however

Last edited by MiKE41 : 09-21-07 at 05:01 PM.
  Reply With Quote
09-21-07, 06:15 PM   #4
Kaomie
A Scalebane Royal Guard
 
Kaomie's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 438
Originally Posted by MiKE41
Edit: Just tried it, doesn't change anything at all. Thanks for the idea however
Okay, according to http://www.wowwiki.com/UI_Code_Load_...dOn_Load_Order it could have:
2. If the AddOn has any un-loaded dependencies, process each of those in the order they appear in the .toc
But I have no clue how PitBull loads, it may delay the frames creation itself too.
__________________
Kaomie
"WE LOTS OF PEOPLE FROM STRONG SERVER GUILDS" - Trade Channel
  Reply With Quote
09-21-07, 06:38 PM   #5
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
it's because of the way PitBull recycles it's frames and when they are created.
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
10-10-07, 10:39 AM   #6
Taffu
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 149
You could also try using the ADDON_LOADED and VARIABLES_LOADED events to check the args to see if Pitbull and it's variables are loaded. If the variables are loaded, then you're addon should be able to find the frames. Just makes sure your Party() and NotParty() functions aren't activating unless you've checked the status of the addon(s) it's dependant on being loaded.
  Reply With Quote
10-11-07, 10:15 PM   #7
Eidolarr
An Aku'mai Servant
 
Eidolarr's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 34
You can make a timer pretty easily, sure, but the real solution is to look at Pitbull's code and see how you can do what you want to do through Pitbull, or at least in a way that doesn't fight with Pitbull.
Code:
local timeleft = 10 --set the countdown to w/e you want
local f = CreateFrame("Frame", nil, UIParent)
f:SetScript("OnUpdate", function(_,arg)
  timeleft = timeleft - arg
  if timeleft >= 0 then
    timeleft = nil
    f:SetScript("OnUpdate", nil)
    --your function call here
  end
end)
Again, that's a terribly hackish solution and I wouldn't recommend it, but it ought to put you in the right direction.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » OnLoad delay


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