Quantcast
Using a value in a frame name - WoWInterface
Thread Tools Display Modes
10-13-10, 08:12 AM   #1
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Using a value in a frame name

Hellor everyone, I'm trying to use a vaule I'm getting from an event to modify a frame name. But I don't really know how and I can't seem to find any info about it.
Code:
elseif (event == "RUNE_POWER_UPDATE" and InCombatLockdown()) and not UnitInVehicleControlSeat("player"))
	local runeIndex, isEnergize = ...
				
	if isEnergize == 1 then
		RuneButtonIndividualX:SetAlpha(RHaic)
How can you change X to be runeIndex? I realise you can't just do RuneButtonIndividualruneIndex since that would be kinda, well weird. Since the EU servers is down right now so I can't test anything so I went here and now I'm hoping for a quick answer

Thanks in advance
Ereki
  Reply With Quote
10-13-10, 08:44 AM   #2
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
_G is a table in the wow enviroment that contains EVERY global object... variables, function calls, frames, tables, everything

and because _G is a table, you can access it like

_G["RuneButtonIndividual"..x]:SetAlpha() --x is a number variable :P


hope that helps
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-13-10, 09:01 AM   #3
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Cool I didn't know that, thanks a bunch!
  Reply With Quote
10-13-10, 01:44 PM   #4
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Ok so I've got some more troubles and I'm turning here again since it worked out great last time.
Code:
if isEnergize == true then
	_G["RuneButtonIndividual"..runeIndex]:SetAlpha(RHaic)
end
Right now I have this tied to the RUNE_POWER_UPDATE event and isEnergized is a valid variable but it won't set the alpha to 1 (which is what RHaic is). As far as I can tell RUNE_POWER_UPDATE seem to fire twice when a rune is energized, first the engerize event and the right after another and since GetRuneCooldown() still returns a cooldown even after it's energized another piece of my code just puts it back to the old alpha value. So I was thinking that I need to delay the SetAlpha() but I'm not sure how to do it, I'm guessing it has to do with OnUpdate, but I need some help with it.
(The whole lua file: http://www.pastey.net/141533 I know it's messy but I got bigger issues right now :p)

PS
Sorry for the double post but I figured it's better than making a whole new thread
  Reply With Quote
10-13-10, 04:52 PM   #5
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
not a problem, sorry for the delay in response as well.

you could simply try

Code:
local lastAlpha = 0
--this is just for proper scoping of this variable, so it saves between function calls
...

function foo()--this is the function where the snippet below is contained

if isEnergize == true and lastAlpha+2<GetTime() then
	_G["RuneButtonIndividual"..runeIndex]:SetAlpha(RHaic)
        lastAlpha = GetTime()
end

end
if isEngerize is true, and the last time we changed the alpha (lastAlpha) is less than 2 seconds ago, then we ignore the function call.

so if we are running through the code

lua Code:
  1. local isEnergize = true
  2. local lastAlpha = 0
  3. GetTime()--outputs 100 in this example, real values will likely be in the 6 digits
  4.  
  5. if isEnergize is true and lastAlpha (which is 0) + 2 (total of 2) is lessthan 100 then do the if statement
  6. set the alpha and now store lastAlpha as 100
  7.  
  8. now the event is called 1 second later
  9.  
  10. if isEnergize is true and lastAlpha(which is 100) + 2 (total of 102) is less than 101 (because it was called one second later, and now GetTime() outputs 101) then do the if statement, however it returns false.
and now your function is no longer called i would set the 2 alot lower, i just wanted to use whole numbers for ease of explaniation... let me know if this isnt clear, I'm bad at explaining things lol
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-14-10, 09:28 AM   #6
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
That's not really my problem, I didn't explain it properly when a rune is energized RUNE_POWER_UPDATE fires twice as I said but it's only the first time isEnergized is true, the second time it's nil and it's that second that I thought put the alpha back. But I modified what you said to:
Code:
elseif event == "RUNE_POWER_UPDATE" and InCombatLockdown() and not UnitInVehicleControlSeat("player") then
	local runeIndex, isEnergize = ...
			
	if isEnergize == true then
		G["RuneButtonIndividual"..runeIndex]:SetAlpha(RHaic)
		lastAlpha = GetTime()
	elseif lastAlpha+1 < GetTime() then
		if GetRuneCooldown(1) > 0 then
			RuneButtonIndividual1:SetAlpha(RHaoc) else 
			RuneButtonIndividual1:SetAlpha(RHaic)
		end
		if GetRuneCooldown(2) > 0 then
			RuneButtonIndividual2:SetAlpha(RHaoc) else 
			RuneButtonIndividual2:SetAlpha(RHaic)
		end
		if GetRuneCooldown(3) > 0 then
			RuneButtonIndividual3:SetAlpha(RHaoc) else 
			RuneButtonIndividual3:SetAlpha(RHaic)
				end										--Cooldown fading	
		if GetRuneCooldown(4) > 0 then
			RuneButtonIndividual4:SetAlpha(RHaoc) else 
			RuneButtonIndividual4:SetAlpha(RHaic)
		end
		if GetRuneCooldown(5) > 0 then
			RuneButtonIndividual5:SetAlpha(RHaoc) else 
			RuneButtonIndividual5:SetAlpha(RHaic)
		end
		if GetRuneCooldown(6) > 0 then
			RuneButtonIndividual6:SetAlpha(RHaoc) else 
			RuneButtonIndividual6:SetAlpha(RHaic)
		end
	end
And it still won't change the alpha so I might have been completely wrong, this is the whole lua file: http://www.pastey.net/141593
And I need some help in figuring out what the hell is wrong 'cause I'm out of ideas.
  Reply With Quote
10-14-10, 02:38 PM   #7
Vrul
An Onyxian Warder
 
Vrul's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2007
Posts: 361
I have no way to test this but you could try:
Code:
local frame = CreateFrame('Frame')
frame:Hide()

for index = 1, MAX_RUNES do
	frame[index] = _G['RuneButtonIndividual' .. index]
end

local OnEvent(self, event, arg1, arg2)
	if event == 'RUNE_POWER_UPDATE' then
		local _, _, isReady = GetRuneCooldown(arg1)
		self[arg1]:SetAlpha(isReady and RHaic or RHaoc)
	elseif event == 'PLAYER_REGEN_DISABLED' then
		self:RegisterEvent('RUNE_POWER_UPDATE')
		local isReady, _
		for index = 1, MAX_RUNES do
			_, _, isReady = GetRuneCooldown(index)
			self[index]:SetAlpha(isReady and RHaic or RHaoc)
		end
	elseif event == 'PLAYER_REGEN_ENABLED' then
		self:UnregisterEvent('RUNE_POWER_UPDATE')
		for index = 1, MAX_RUNES do
			self[index]:SetAlpha(RHaoc)
		end
	end
end

frame:SetScript('OnEvent', OnEvent)
frame:RegisterEvent('PLAYER_REGEN_DISABLED')
frame:RegisterEvent('PLAYER_REGEN_ENABLED')

OnEvent(InCombatLockdown() and 'PLAYER_REGEN_DISABLED' or 'PLAYER_REGEN_ENABLED')
  Reply With Quote
10-14-10, 03:13 PM   #8
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Thanks Vrul but just gonna check somethings here, first isn't that just a replacement for the "if GetRuneCooldown(1) > 0 then" part? 'Cause that's working fine it's the energize part that's the problem (energize is when a rune is refreshed by either Runic Empowerment, Blood Tap or Empower Rune Weapon) right now the alpha stays the same and I just see the glow for it, what I want is to change the alpha to RHaic when they are energized.
And if it's working with that then i just wonder what is "OnEvent(InCombatLockdown() and 'PLAYER_REGEN_DISABLED' or 'PLAYER_REGEN_ENABLED')" is for, never seen anything like that before
  Reply With Quote
10-15-10, 06:02 AM   #9
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
okay i tried this on live servers and i noticed something weird... RUNE_POWER_UPDATE always passes false for the 2nd arguement (which you store into isEnergized

I spammed only frost rune so I could look at it better, but when I cast Icy touch it would call the event, and when I cast it again it would call it once to try the first frost rune, and again for the 2nd one.

/run test = CreateFrame("Frame") test:RegisterEvent("RUNE_POWER_UPDATE") test:SetScript("OnEvent", function(self,event,arg1,arg2) print(event,arg1,arg2 or "false") for i=5, 6 do print(GetTime(),GetRuneCooldown(i)) end end)

this would output

Code:
--first Icy Touch
RUNE_POWER_UPDATE 5 false
93345.183 93345.183 10 false --time called, 10 sec CD, false (false being ready)
93345.183 0 10 true -- 0 because this rune wasnt called, 10 sec CD, true (rune is ready)
--second Icy Touch
RUNE_POWER_UPDATE 5 false
93347.799 93345.172 10 false
93347.799 0 10 true
RUNE_POWER_UPDATE 5 false
93347.8 93345.173 10 false
93347.8 0 10 true
RUNE_POWER_UPDATE 6 false
93347.801 93345.173 10 false
93347.801 93355.172 10 false --these 2 numbers are 10 apart...
timestamps are in yellow, that is when i pushed the 2nd icy touch, so the last 3 numbers are within 0.003 seconds of each other.

hopefully that call order will help debug on whats actually happening
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>

Last edited by Xubera : 10-15-10 at 06:09 AM.
  Reply With Quote
10-15-10, 06:42 AM   #10
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
I think you're missunderstanding what isEnergized is for, isEnergized is true when a rune becomes ready throguh one of three methods: Blood Tap, Runic Empowerment or Empower Rune Weapon. So it will never be true when you just spam rune abilities, what makes it weird and hard for me to get an idea what to do is that GetRuneCooldown() still returns the cooldown the rune should've had if it was energized.

But I'm gonna do some testing with the help of that script.

Last edited by Ereki : 10-15-10 at 06:51 AM. Reason: Spelling
  Reply With Quote
10-15-10, 06:58 AM   #11
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
oh i see, i was testing on a level 55 dk... ive never had one before xD

well instead of lastAlpha holding a time, make it hold a rune index

Code:
if isEnergize == true then
	_G["RuneButtonIndividual"..runeIndex]:SetAlpha(RHaic)
        lastAlpha = runeIndex
else then
                if lastAlpha == nil then lastAlpha = false end --if we dont have the variable defined yet, define it.
		if GetRuneCooldown(1) > 0 and lastAlpha ~= 1 then
			RuneButtonIndividual1:SetAlpha(RHaoc) else 
			RuneButtonIndividual1:SetAlpha(RHaic)
		end
		if GetRuneCooldown(2) > 0 and lastAlpha ~= 2 then
			RuneButtonIndividual2:SetAlpha(RHaoc) else 
			RuneButtonIndividual2:SetAlpha(RHaic)
		end
		if GetRuneCooldown(3) > 0 and lastAlpha ~= 3 then
			RuneButtonIndividual3:SetAlpha(RHaoc) else 
			RuneButtonIndividual3:SetAlpha(RHaic)
				end
		if GetRuneCooldown(4) > 0 and runeIndex ~= 4 then
			RuneButtonIndividual4:SetAlpha(RHaoc) else 
			RuneButtonIndividual4:SetAlpha(RHaic)
		end
		if GetRuneCooldown(5) > 0 and lastAlpha ~= 5 then
			RuneButtonIndividual5:SetAlpha(RHaoc) else 
			RuneButtonIndividual5:SetAlpha(RHaic)
		end
		if GetRuneCooldown(6) > 0 and lastAlpha ~= 6 then
			RuneButtonIndividual6:SetAlpha(RHaoc) else 
			RuneButtonIndividual6:SetAlpha(RHaic)
		end
                lastAlpha = false --clears it, so it doesnt hold the number when its not active by energization.
	end
that way if the cooldown is over 0 and it was just energized, then it keeps the alpha

also lastAlpha is being set to false... not nil

if lastAlpha is nil then lastAlpha == 1 will throw an error
if lastAlpha is false then lastAlpha == 1 will throw false
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-15-10, 07:05 AM   #12
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
It still doesn't change the alpha so it has to be something else that's screwing with it, this is the result I got with the script btw:

[14:52:06] RUNE_POWER_UPDATE 1 true
[14:52:06] 6435.517 6426.055 10 false
[14:52:06] 6435.517 6436.054 10 false
[14:52:06] RUNE_POWER_UPDATE 2 false
[14:52:06] 6435.518 6426.055 10 false
[14:52:06] 6435.518 6436.054 10 false
[14:52:06] RUNE_POWER_UPDATE 1 false
[14:52:06] 6435.53 6426.055 10 false
[14:52:06] 6435.531 6436.054 10 false

As you can see the evenet even fires three times when using blood tap, first is the rune getting energized, second and third I have no idea why they fires.

PS
I edited the script to show the cooldown of rune 1 and 2 instead of 5 and 6.
  Reply With Quote
10-15-10, 08:30 AM   #13
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
does it work when you arent trying to energize? like in a normal situation, does that addon work as intended, then the alpha comes from those cooldowns?
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-15-10, 08:31 AM   #14
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Ye the normal cooldowns work just fine, it's just the egerize part (which was introduced in 4.0.1) that's not working
  Reply With Quote
10-15-10, 08:34 AM   #15
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
ya know, you said the time is screwy when the energization happens, what if we see if the rune is ready

Code:
for i=1,6 do
    local isReady = select(3,GetRuneCooldown(i))
    if isReady then
      _G["RuneButtonIndividual"..i]:SetAlpha(RHaic) --setalpha to 1
    else
       _G["RuneButtonIndiviudal"..i]:SetAlpha(RHaoc) --setalpha 0.2
    end
end
or does the script say that its false as well even through its ready
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote
10-15-10, 08:38 AM   #16
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
another thing, you said it called twice after the energization, then we cant clear the lastAlpha like that... we need to find another way to clear it, maybe

lastUpdate = 0--time
lastAlpha = false -- rune

then we add at the top of the elseif

if lastUpdate + 2 < GetTime() then lastAlpha = false end

and in the if isEnergized == true statement add a
lastUpdate = GetTime()


so what im envisioning is

Code:
local runeIndex, isEnergize = ...
			
	if isEnergize == true then
		G["RuneButtonIndividual"..runeIndex]:SetAlpha(RHaic)
		lastAlpha = runeIndex
        lastUpdate = GetTime()
	else 
        if lastUpdate and lastUpdate + 2 < GetTime() then lastAlpha = false end
        if lastAlpha = nil then lastAlpha = false end
		for i=1,6 do
            if lastAlpha ~= i then
                local isReady = select(3,GetRuneCooldown(i))
                if isReady then
                     _G["RuneButtonIndividual"..i]:SetAlpha(1) --RHaic
                else
                          _G["RuneButtonIndiviual"..i]:SetAlpha(0.2) -- RHaoc
                end
            end
        end
     end
EDIT: Going to work, let me know if those helped out any, but ill be getting off 6pm Pacific
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>

Last edited by Xubera : 10-15-10 at 09:22 AM.
  Reply With Quote
10-15-10, 11:12 AM   #17
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
[14:52:06] RUNE_POWER_UPDATE 1 true
[14:52:06] 6435.517 6426.055 10 false
[14:52:06] 6435.517 6436.054 10 false
[14:52:06] RUNE_POWER_UPDATE 2 false
[14:52:06] 6435.518 6426.055 10 false
[14:52:06] 6435.518 6436.054 10 false
[14:52:06] RUNE_POWER_UPDATE 1 false
[14:52:06] 6435.53 6426.055 10 false
[14:52:06] 6435.531 6436.054 10 false
There's the results from the script so yeah it says false even though it is ready and I shouldn't need that last thing since the evenet only fires one additional time for the same rune, the last event is for the other rune of the same type. But I have no idea why it fires for that rune, I'm a bit confused to why blizzard have done it this way if I'm honest.
  Reply With Quote
10-15-10, 12:50 PM   #18
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Tried that and I got the same bug as when I tried to use just _G["RuneButtonIndividual"..i] for setting the alpha when they go on cooldown which is it only fades the first rune I use and then ignores the rest and it doesn't turn the alpha up for the rune it faded once it's ready again either. When I changed it to:
Code:
local runeIndex, isEnergize = ...
			
if isEnergize == true then
	G["RuneButtonIndividual"..runeIndex]:SetAlpha(RHaic)
	lastAlpha = runeIndex
	lastUpdate = GetTime()
else 
	if lastUpdate and lastUpdate + 2 < GetTime() then lastAlpha = false end
	if lastAlpha == nil then lastAlpha = false end

	if GetRuneCooldown(1) > 0 and lastAlpha ~= 1 then
		RuneButtonIndividual1:SetAlpha(RHaoc) else 
		RuneButtonIndividual1:SetAlpha(RHaic)
	end
	if GetRuneCooldown(2) > 0 and lastAlpha ~= 2 then
		RuneButtonIndividual2:SetAlpha(RHaoc) else 
		RuneButtonIndividual2:SetAlpha(RHaic)
	end
	if GetRuneCooldown(3) > 0 and lastAlpha ~= 3 then
		RuneButtonIndividual3:SetAlpha(RHaoc) else 
		RuneButtonIndividual3:SetAlpha(RHaic)
	end
	if GetRuneCooldown(4) > 0 and runeIndex ~= 4 then
		RuneButtonIndividual4:SetAlpha(RHaoc) else 
		RuneButtonIndividual4:SetAlpha(RHaic)
	end
	if GetRuneCooldown(5) > 0 and lastAlpha ~= 5 then
		RuneButtonIndividual5:SetAlpha(RHaoc) else 
		RuneButtonIndividual5:SetAlpha(RHaic)
	end
	if GetRuneCooldown(6) > 0 and lastAlpha ~= 6 then
		RuneButtonIndividual6:SetAlpha(RHaoc) else 
		RuneButtonIndividual6:SetAlpha(RHaic)
	end
end
I got the exact same results as I've had every time before :p
  Reply With Quote
10-21-10, 05:22 AM   #19
Ereki
A Fallenroot Satyr
AddOn Author - Click to view addons
Join Date: Apr 2008
Posts: 24
Still need help with this, does anyone have a clue what I can do?
  Reply With Quote
10-21-10, 02:35 PM   #20
Xubera
A Cobalt Mageweaver
 
Xubera's Avatar
AddOn Author - Click to view addons
Join Date: May 2009
Posts: 207
look at bliz's code... i dont play a DK, but i look through the images, and they have speccial images for energized runes... see how they do it. How they make the image appear and then stay put until its used or w/e
__________________
Chat Consolidate is the solution to any out of control trade chat. Ignore lines, throttle chat, consolidate posts!Follow the link to find out how!

▲ ▲ WoWInterface wont let me triforce >.>
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Using a value in a frame name

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