Thread Tools Display Modes
10-20-13, 07:53 AM   #1
CrazyCactuaR
A Deviate Faerie Dragon
Join Date: Oct 2011
Posts: 13
Unhappy Stuck on using table varibles

Hi all and thanks for reading/helping.

Code:
local p="Player"
my = {
	Class = UnitClass(p),
	Level = UnitLevel(p),
	Spec = GetSpecialization(p),
}

local t="Target"
tar = {
	Class = UnitClass(t),
	Level = UnitLevel(t),
	Spec = GetSpecialization(t),
}
Using this code WoW will happily work if i do my.Class, my.Level or my.Spec. However doing tar.Class/tar.Level/tar.Spec all return nil even with a selected target. Manually using UnitClass(t) will also work.

So my question is since i have no idea why this doesnt work is why, and how do i solve it?

Thank you
  Reply With Quote
10-20-13, 08:01 AM   #2
Rilgamon
Premium Member
 
Rilgamon's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Sep 2009
Posts: 822
This code runs at load time. At this time you dont have a target.
You need to react to an event and update this table when the event occurs.
"PLAYER_TARGET_CHANGED" is such an event.

Lua Code:
  1. local f = CreateFrame("Frame")
  2. local tar
  3. f:RegisterEvent("PLAYER_TARGET_CHANGED")
  4. f:SetScript("OnEvent", function(self, event)
  5. local t="target"
  6. tar = {
  7.     Class = UnitClass(t),
  8.     Level = UnitLevel(t),
  9.     Spec = GetSpecialization(t),
  10. }
  11. end)
__________________
The cataclysm broke the world ... and the pandas could not fix it!
  Reply With Quote
10-20-13, 08:02 AM   #3
CrazyCactuaR
A Deviate Faerie Dragon
Join Date: Oct 2011
Posts: 13
Originally Posted by Rilgamon View Post
This code runs at load time. At this time you dont have a target.
You need to react to an event and update this table when the event occurs.
"PLAYER_TARGET_CHANGED" is such an event.

Lua Code:
  1. local f = CreateFrame("Frame")
  2. local tar
  3. f:RegisterEvent("PLAYER_TARGET_CHANGED")
  4. f:SetScript("OnEvent", function(self, event)
  5. local t="target"
  6. tar = {
  7.     Class = UnitClass(t),
  8.     Level = UnitLevel(t),
  9.     Spec = GetSpecialization(t),
  10. }
  11. end)
ah i see, I always thought it would work even if i had a target. Thank you for that
  Reply With Quote
10-20-13, 08:15 AM   #4
Rainrider
A Firelord
AddOn Author - Click to view addons
Join Date: Nov 2008
Posts: 454
Also, you won't get your target's spec with GetSpezialisation(). You'll need to use GetInspectSpezialisation() for which you'll have to query an inspect on the target unit and wait for the INSPECT_READY event.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Stuck on using table varibles


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