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: 25
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: 25
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: 25
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: 25
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

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