Thread Tools Display Modes
06-04-14, 03:48 PM   #1
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
Parenting/Anchoring issues

Alright so I am working on an addon which sets up the configuration of the addons within my compilation and sets up custom frames. I am working on a little bit at a time so it isn't quite finished yet. Anyway everything has been working as expected except for a custom background frame I made for the Player frame. I am using ShadwedUnitFrames and upon using "/fstack" revealed that the frame name for the player frame is "SUFUnitplayer". The code is supposed to check if "ShadowedUnitFrames' is loaded and is so, load my custom frame and parent/anchor it to the player frame. However, when I load the game nothing shows up and no errors come up either (using bugGrabber/bugSack).

Note: I have attached the entire addon, but here is a snippet of the code referring to the relevant frames:

Code:
function LCI:frame_unitPlayer()
	
	--Player Frame Settings
	local LCIPlayer = CreateFrame("Frame", "LCI_Player", SUFUnitplayer)
	LCIPlayer:SetPoint("CENTER", SUFUnitplayer, 0, 0)
	LCIPlayer:SetSize(1000, 1000)
	LCIPlayer:SetScale(1)
	LCIPlayer:SetFrameStrata("BACKGROUND")
	LCIPlayer:SetFrameLevel("5")
	
	--Player Frame Background
	LCIPlayer.bg = LCIPlayer:CreateTexture(nil, "ARTWORK")
	LCIPlayer.bg:SetTexture(MEDIAPATH .. "bg_player")
	if LCI.db.profile.LCI_ScaleTypeSet == "1920x1080" then
		LCIPlayer.bg:SetPoint("CENTER", SUFUnitplayer, 0, 0)
		LCIPlayer.bg:SetSize(500, 500)
	end
	
end

local check_units = CreateFrame("Frame", nil, UIParent)
check_units:RegisterEvent("ADDON_LOADED")
check_units:SetScript("OnEvent", function(self, event, AddOn)
	if AddOn == "ShadowedUnitFrames" then	
		LCI:frame_unitPlayer()
	end
end)
Attached Files
File Type: zip LCI.zip (669.9 KB, 156 views)
  Reply With Quote
06-04-14, 10:45 PM   #2
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
I didn't look through your entire addon, but the most likely cause of the problem you described is that SUF doesn't create its frames right away when it loads -- it probably waits for PLAYER_LOGIN or some other later event, which means that your addon needs to do the same. However, there's no guarantee that registering for the same event will make your event handler run after SUF's event handler, so the best solution here would be to just hook the SUF function that creates the frames, eg. if that method is "ShadowedUF:MakeAFrame(unit)" then you'd hook it like so:

Code:
if ShadowedUF then
     hooksecurefunc(ShadowedUF, "MakeAFrame", function(ShadowedUF, unit)
          if unit == "player" then
               -- SUFUnitplayer has already been created by the original function, do what you want with it here
          end
     end)
end
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.
  Reply With Quote
06-05-14, 09:45 AM   #3
Vrul
A Scalebane Royal Guard
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 404
What Phanx posted should fix your problem (provided you hook the correct function). Another reason the code you posted wouldn't have worked is that the ADDON_LOADED event would have fired for ShadowedUnitFrames before your addon even loaded and registered for the event to look for it.
  Reply With Quote
06-06-14, 01:24 AM   #4
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
I am having trouble figuring out the function to hook. I had some high hopes when I found https://github.com/Shadowed/Shadowed...ons-and-fields. This lead me to write this:

Code:
local check_units = CreateFrame("Frame", nil, UIParent)
check_units:RegisterEvent("ADDON_LOADED")
check_units:SetScript("OnEvent", function(self, event, AddOn)
	if AddOn == "ShadowedUnitFrames" then	
		hooksecurefun(frame, "RegisterUpdateFunc", function(frame)
			if frame == "SUFUnitplayer" then
				LCI:frame_unitPlayer()
			end
		end)
	end
end)
This didn't work... I'm stumped for now. Going to get some sleep and try again tomorrow.
  Reply With Quote
06-06-14, 02:24 AM   #5
Phanx
Cat.
 
Phanx's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2006
Posts: 5,617
Your code doesn't work because:

1. You have a typo. There is no such function as "hooksecurefun" -- it needs a "c" on the end. Your code should be raising an "attempt to call a nil value" error here. If you don't already have BugSack, go get it now. Trying to write or edit addon code without it (or some other tool to show you Lua errors, and no, the default error display is not good enough) is kind of like trying to assemble a jigsaw puzzle while wearing a blindfold -- technically you can do it, but why would you want to torture yourself?

2. You're passing a variable "frame" that you didn't define anywhere, which means you're looking for it in the global namespace. Ideally it should not exist there either, but since it's so generic, it's reasonably possible that some other addon (or even the default UI) is leaking a variable with that name, in which case the odds are probably better that you'll win the lottery and also gain telekinetic superpowers after being attacked by flying radioactive unicorn kittens than that the leaked "frame" variable will be pointing to a table with a "RegisterUpdateFunc" method attached to it. If no other addons are leaking a "frame" variable, this should also be raising a Lua error.

3. The function you're passing accepts only one argument, which you've also named "frame", which is problematic because:

3a. A function named "RegisterUpdateFunc" probably does not accept a frame name or reference as its only argument. It's far more likely that it requires a function as its only argument, and more likely still that it requires multiple arguments including a function. Post-hook functions get the same exact arguments as the original function, so do take note of what arguments the function you're hooking receives, or if you're not going to use any of the arguments, don't bother naming any.

3b. An argument named "frame" is far more likely to be a frame reference than a frame name, and comparing a frame reference to a frame name -- eg. if UIParent == "UIParent" then -- will always fail, because a frame name cannot be equal to a string.

4. If you've already declared SUF as an optional dependency for your addon, or if your addon's name comes after SUF in alphabetical order, or SUF loaded before your addon for some other reason, then your addon will never receive an ADDON_LOADED event for SUF, because by the time WoW even figures out that your addon exists, SUF has already loaded.

-----------------------------------------------------------------------------

Here's what you need to do:

1. Add ShadowedUnitFrames to the OptionalDependencies field in your addon's TOC file if you haven't already. If your addon is skinning, or anchoring things to things from, more than 3-5 addons, skip this step.

2. Add this code somewhere in your addon:

Code:
local function DoStuff()
     -- do stuff with the SUFUnitplayer frame here
end

if SUFUnitplayer then
     DoStuff()
elseif ShadowUF then
     hooksecurefunc(ShadowUF.Units, "LoadUnit", function(self, unit)
          if unit == "player" then
               DoStuff()
          end
     end)
end
3. If you skipped Step 1, add this right before the final "end" in the code above:

Code:
else
     local f = CreateFrame("Frame")
     f:RegisterEvent("ADDON_LOADED")
     f:SetScript("OnEvent", function(self, event, addon)
          if addon == "ShadowedUnitFrames" then
               hooksecurefunc(ShadowUF.Units, "LoadUnit", function(self, unit)
                    if unit == "player" then
                         DoStuff()
                    end
               end)
          end
     end)
__________________
Retired author of too many addons.
Message me if you're interested in taking over one of my addons.
Don’t message me about addon bugs or programming questions.

Last edited by Phanx : 06-06-14 at 02:27 AM.
  Reply With Quote
06-06-14, 09:25 AM   #6
WhiteWolf87
A Deviate Faerie Dragon
 
WhiteWolf87's Avatar
AddOn Compiler - Click to view compilations
Join Date: Dec 2013
Posts: 16
Yea sorry I was really tired... just added the code like you said and it worked great! Thank you so much, you are a life saver.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Parenting/Anchoring issues


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