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:
jps_tableSpec =
{
[250]="Blood", [251]="Frost", [252]="Unholy", [102]="Balance", [103]="Feral",
[104]="Guardian", [105]="Restoration", [253]="Beast Mastery", [254]="Marksmanship",
[255]="Survival", [62]="Arcane", [63]="Fire", [64]="Frost", [268]="Brewmaster",
[270]="Mistweaver", [269]="Windwalker", [65]="Holy", [66]="Protection",
[70]="Retribution", [256]="Discipline", [257]="Holy", [258]="Shadow",
[259]="Assassination", [260]="Combat", [261]="Subtlety", [262]="Elemental",
[263]="Enhancement", [264]="Restoration", [265]="Affliction", [266]="Demonology",
[267]="Destruction", [71]="Arms", [72]="Fury", [73]="Protection",
[0]="Unknown Spec"
}
local f = CreateFrame("Frame")
f:SetScript("OnEvent",function(self, event, ...)
if self[event] then
self[event](self, ...) -- Call the method with the same name as the event. (INSPECT_READY fires the f:INSPECT_READY(...) method)
end
end)
f:RegisterEvent("INSPECT_READY")
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.
local unit = self.unit
if unit and UnitGUID(unit) == guid then
self.unit = nil
local specID = GetInspectSpecialization(unit)
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.
print(specID, "-", UnitName(unit), "is", jps_tableSpec[specID], "-", enemyClass, "-", enemySpec, "-", enemyRole)
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.
end
end
function f:InspectReadyCallback(unit, specID, enemySpec, enemyRole, enemyClass) -- Called when INSPECT_READY fires for the unit we inspected
-- Do some stuff with the information we received from the inspection
end
function jps_EnemySpec_BG(unit)
if not UnitExists(unit) then unit = "player"
else unit = "target" end
if CheckInteractDistance(unit,1) then
f.unit = unit
NotifyInspect(unit)
end
end