Thread Tools Display Modes
03-13-11, 03:23 PM   #1
DrGlenn
A Kobold Labourer
 
DrGlenn's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 1
Hooking into OnUpdate for moving unitframes

I've been fiddling with a very basic UI modification where I need to scale and move the default unitframes.

I initially just made a macro for re-scaling and re-positioning the unitframes, but wanted something more permanent to avoid having to run the macro after each loading screen. I tried using a wide variety of "move anything"-addons out there, but they all had issues with vehicle unitframes.

I tried to come up with my own solution, and ended up with the following bit of code, which actually works even with vehicle unitframes:

Code:
local timer = 2

local f = CreateFrame("Frame")



f:SetScript("OnUpdate", function(self, elapsed)

  timer = timer - elapsed

  if (timer > 0) then return end

 PlayerFrame:SetScale(1.1)

 PetFrame:SetScale(1.1)

 FocusFrame:SetScale(1.1)

 TargetFrame:SetScale(1.1)

 PlayerFrame:ClearAllPoints() 

 PlayerFrame:SetPoint("CENTER", -250, -150)

 TargetFrame:ClearAllPoints() 

 TargetFrame:SetPoint("CENTER", 250, -150)

 FocusFrame:ClearAllPoints() 

 FocusFrame:SetPoint("CENTER", -500, -150)


 timer = timer + 2 -- or just timer = 5 if you don't need to be super exact

end)
My question is: would this be considered bad programming practice, considering the way I'm hooking into OnUpdate ? This is pretty much my first time working with LUA for WoW, so I'm worried that the code could be a resource-hog
  Reply With Quote
03-13-11, 04:23 PM   #2
Chibi
A Cyclonian
 
Chibi's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 43
You might try using one of the events related to entering the world or addons being loaded. Trying to do it on-update will try to do it every frame, and throw errors when it fires in combat for frames that can't be moved then.
__________________
Perhaps...
  Reply With Quote
04-18-11, 12:23 PM   #3
bjp91
A Defias Bandit
 
bjp91's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2009
Posts: 3
Originally Posted by Chibi View Post
You might try using one of the events related to entering the world or addons being loaded. Trying to do it on-update will try to do it every frame, and throw errors when it fires in combat for frames that can't be moved then.
Yeah the ideal way to set up this would be

Code:
local f = CreateFrame("Frame")
f:RegisterEvent("PLAYER_ENTERING_WORLD")
f:SetScript("OnEvent", function(self, event)
	PlayerFrame:SetScale(1.1)
	PetFrame:SetScale(1.1)
	FocusFrame:SetScale(1.1)
	TargetFrame:SetScale(1.1)
	PlayerFrame:ClearAllPoints() 
	PlayerFrame:SetPoint("CENTER", -250, -150)
	TargetFrame:ClearAllPoints() 
	TargetFrame:SetPoint("CENTER", 250, -150)
	FocusFrame:ClearAllPoints() 
	FocusFrame:SetPoint("CENTER", -500, -150)
end)
  Reply With Quote
04-18-11, 02:54 PM   #4
Mischback
A Cobalt Mageweaver
 
Mischback's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2009
Posts: 221
OnUpdate is the very last spot you should do stuff like this, because it is run way too often.

As mentioned: Use PLAYER_ENTERING_WORLD and perhaps disable the SetPoint-functions for the frames in question by setting

lua Code:
  1. frame.SetPoint = function() return end
__________________
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Hooking into OnUpdate for moving unitframes

Thread Tools
Display Modes

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