View Single Post
Unread 01-06-13, 03:45 PM   #6
Choonstertwo
A Flamescale Wyrmkin
 
Choonstertwo's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2011
Posts: 131
Apart from the issues the others mentioned, the local variables you're trying to return the values of are out of the scope of the return statement. When you use the local keyword, the local variable is created for the innermost block and isn't visible to any code outside of the block.

The manual explains this well:
http://www.lua.org/manual/5.1/manual.html#2.6

Your local variables are defined in the innermost if block, but the return statement that tries to access them is outside of that block, meaning it accesses global variables of the same name (which are nil in this case).

Here's an untested example of what your code could look like:
Lua Code:
  1. jps_tableSpec =
  2. {
  3.   [250]="Blood", [251]="Frost", [252]="Unholy", [102]="Balance", [103]="Feral",
  4.   [104]="Guardian", [105]="Restoration", [253]="Beast Mastery", [254]="Marksmanship",
  5.   [255]="Survival", [62]="Arcane", [63]="Fire", [64]="Frost", [268]="Brewmaster",
  6.   [270]="Mistweaver", [269]="Windwalker", [65]="Holy", [66]="Protection",
  7.   [70]="Retribution", [256]="Discipline", [257]="Holy", [258]="Shadow",
  8.   [259]="Assassination", [260]="Combat", [261]="Subtlety", [262]="Elemental",
  9.   [263]="Enhancement", [264]="Restoration", [265]="Affliction", [266]="Demonology",
  10.   [267]="Destruction", [71]="Arms", [72]="Fury", [73]="Protection",
  11.   [0]="Unknown Spec"
  12. }
  13.  
  14. local f = CreateFrame("Frame")
  15. f:SetScript("OnEvent",function(self, event, ...)
  16.     if self[event] then
  17.         self[event](self, ...) -- Call the method with the same name as the event. (INSPECT_READY fires the f:INSPECT_READY(...) method)
  18.     end
  19. end)
  20.  
  21. f:RegisterEvent("INSPECT_READY")
  22.  
  23. function f:INSPECT_READY(guid) -- Wowpedia says it has a single GUID argument, WoW Programming says it doesn't. If it doesn't have this argument, get rid of the GUID check below.
  24.     local unit = self.unit
  25.     if unit and UnitGUID(unit) == guid then
  26.         self.unit = nil
  27.         local specID = GetInspectSpecialization(unit)
  28.         local _, enemySpec, _, _, _, enemyRole, enemyClass = GetSpecializationInfoByID(specID) -- It's more efficient to call the function once and use dummy variables for the returns you don't need than to call it once for each return you want.
  29.         print(specID, "-", UnitName(unit), "is", jps_tableSpec[specID], "-", enemyClass, "-", enemySpec, "-", enemyRole)
  30.         self:InspectReadyCallback(unit, specID, enemySpec, enemyRole, enemyClass) -- You can rename this and reorganise the arguments to your liking, just make sure you change its definition below.
  31.     end
  32. end
  33.  
  34. function f:InspectReadyCallback(unit, specID, enemySpec, enemyRole, enemyClass) -- Called when INSPECT_READY fires for the unit we inspected
  35.     -- Do some stuff with the information we received from the inspection
  36. end
  37.  
  38. function jps_EnemySpec_BG(unit)
  39.     if not UnitExists(unit) then unit = "player"
  40.     else unit = "target" end
  41.  
  42.     if CheckInteractDistance(unit,1) then
  43.         f.unit = unit
  44.         NotifyInspect(unit)
  45.     end
  46. end
Choonstertwo is offline   Reply With Quote