ok thank you didn't think about that as I just tend to put all my functions and stuff into tables and use local variables inside my functions all the time.
Guess I have some optimization to be gained then :)
I have noticed while developing on my addon that sometimes, when messing with functions which are continuously called from "OnUpdate" frame scripts, the memory usage for my addon start to rise aggressively (like +2kb per sec). I am quiet sure that local variables in the called functions are the guilty ones for this rise in memory usage.
--this stuff is continuously updated
someFrame:SetScript("OnUpdate",
function()
someFunction()
end)
function someFunction()
local var1
local var2
local var3
...
end
I guess new memory for those local variables are allocated all the time, and then the garbage collector kicks in once in a while to clean up and then the rise of memory usage starts over again.
If my assumption is correct, is it then better to refrain from using local variables in such functions and use global ones instead? OR is it best to use local variables because they use less CPU to access compared to global variables?
Access to global variables in for example C programming is CPU expensive, but then again C is stack-based and Lua is register-based-VM...
HUURAAY!!! I made it work, thank you so much for helping out it was great inspiration :)
The Solution:
- create a Frame with 'SecureHandlerStateTemplate' as template.
- setup statedriver and attribute to show and hide the frame based on the [alt] key as modifier.
- create a Button with 'SecureActionButtonTemplate' as template, and the Frame created before as parent.
- create the texture for the button highlight.
- setup 'OnLeave' and 'OnEnter' scripts for the button to show and hide the button texture.
EDIT:
I know its late to post it, but there was a bug in version of my addon which I reffered to earlier, its fxed now:
If you wish to see it in action go download latest alpha of my addon http://wow.curseforge.com/addons/simplehud/files/ (its far from complete yet, but should be relative bug free)
I want to make a ('secure'-)frame which is only click-enabled when the mouse hovers over it while the [alt] key is held down. When the [alt] key is not held down it should be possible to click through the frame. I also want it to be possible to move the frame based on a user defined variable which locks or unlocks the position of the frame.
Furthermore I want the frame to be kind of 'highlighted' when the mouse hovers over it while the [alt] key is held down, and nothing to happen when the mouse hovers over the frame without the [alt] key held down.
The purpose of the frame, is to show information to the player and for the player to be able to target himself with it.
I am pretty new to this 'SecureActionButtonTemplate'-stuff, but I have come up with this piece of code after reading up on it around the net:
SimpleHUD["player"].clickable_Frame = CreateFrame("Button", "player_clickable_Frame", UIParent, "SecureActionButtonTemplate")
SimpleHUD["player"].clickable_Frame:SetAttribute("alt-type1", "target")
SimpleHUD["player"].clickable_Frame:SetAttribute("unit", "player")
SimpleHUD["player"].clickable_Frame:SetScript("OnEnter", function()
if IsAltKeyDown() then
SimpleHUD["player"].barBorder:SetAlpha(0.40)
end
end)
SimpleHUD["player"].clickable_Frame:SetScript("OnLeave", function()
if IsAltKeyDown() then
SHUD_BarFunctions:Update_PlayerAlpha()
end
end)
This works almost the way I want, except that:
- It is not possible to click through the frame when the [alt] key is not held down, it also highlights my character even though the [alt] key isn't activated.
- The frame isn't highlighted when the mouse already hovers over the frame and the [alt] key is pressed.
I think I might be able to fix the frame-highlighting problem, but I can't seem to find a solution to the "click-through" problem.
I have unsuccessful messed around with:
SimpleHUD["player"].clickable_Frame:Disable() / Enable()
SimpleHUD["player"].clickable_Frame:EnableMouse(false) / EnableMouse(true)
My conclusion so far:
I think I have to disable and enable the 'Attribute'-stuff somehow based on whether the [alt] key is activated or not. But I don't know how to reset or disable these 'SetAttribute'-things in a proper way, and I wouldn't be surprised if this really isn't the solution.
I can't seem to find any api function that returns the target of a specific unit, like target of my target... Are there really no such method :S?, and if not then what cowboy tricks do you use to get target of target?
EDIT: Solved it!, yeh I know this post hasn't been up for long but I wont delete it, because maybe someone else has the same problem or run into the same problem (and google totally let me down this time)...
SOLUTION:
Apparently you can write "targettarget" to get target of target, for example: UnitName("targettarget")
0
Guess I have some optimization to be gained then :)
0
I guess new memory for those local variables are allocated all the time, and then the garbage collector kicks in once in a while to clean up and then the rise of memory usage starts over again.
If my assumption is correct, is it then better to refrain from using local variables in such functions and use global ones instead? OR is it best to use local variables because they use less CPU to access compared to global variables?
Access to global variables in for example C programming is CPU expensive, but then again C is stack-based and Lua is register-based-VM...
0
The Solution:
- create a Frame with 'SecureHandlerStateTemplate' as template.
- setup statedriver and attribute to show and hide the frame based on the [alt] key as modifier.
- create a Button with 'SecureActionButtonTemplate' as template, and the Frame created before as parent.
- create the texture for the button highlight.
- setup 'OnLeave' and 'OnEnter' scripts for the button to show and hide the button texture.
EDIT:
I know its late to post it, but there was a bug in version of my addon which I reffered to earlier, its fxed now:
If you wish to see it in action go download latest alpha of my addon http://wow.curseforge.com/addons/simplehud/files/ (its far from complete yet, but should be relative bug free)
0
Furthermore I want the frame to be kind of 'highlighted' when the mouse hovers over it while the [alt] key is held down, and nothing to happen when the mouse hovers over the frame without the [alt] key held down.
The purpose of the frame, is to show information to the player and for the player to be able to target himself with it.
I am pretty new to this 'SecureActionButtonTemplate'-stuff, but I have come up with this piece of code after reading up on it around the net:
This works almost the way I want, except that:
- It is not possible to click through the frame when the [alt] key is not held down, it also highlights my character even though the [alt] key isn't activated.
- The frame isn't highlighted when the mouse already hovers over the frame and the [alt] key is pressed.
I think I might be able to fix the frame-highlighting problem, but I can't seem to find a solution to the "click-through" problem.
I have unsuccessful messed around with:
SimpleHUD["player"].clickable_Frame:Disable() / Enable()
SimpleHUD["player"].clickable_Frame:EnableMouse(false) / EnableMouse(true)
My conclusion so far:
I think I have to disable and enable the 'Attribute'-stuff somehow based on whether the [alt] key is activated or not. But I don't know how to reset or disable these 'SetAttribute'-things in a proper way, and I wouldn't be surprised if this really isn't the solution.
Any help will be appreciated.
0
This is going to be very useful for me :)
0
( My usual api information resource is http://wowprogramming.com/docs/api_categories, but I also looked at http://www.wowwiki.com/World_of_Warcraft_API )
EDIT: Solved it!, yeh I know this post hasn't been up for long but I wont delete it, because maybe someone else has the same problem or run into the same problem (and google totally let me down this time)...
SOLUTION:
Apparently you can write "targettarget" to get target of target, for example: UnitName("targettarget")