get class spec of Enemy Unit in BG
I want to get class & spec of EnemyUnit in BG ( "target", "raid1target"...
the function print correctly the class & Spec but returns nil,nil,nil when I want to use it in an other function.
local unit = "target"
local enemyRole,enemySpec,enemyClass = jps_EnemySpec_BG(unit)
I don't understand why?
Ps jps_tableSpec is a simple table of differnts spec
The simple answer is that enemyRole, enemySpec, and enemyClass haven't been set yet when the function returns their values. The INSPECT_READY event is fired at some point in the future after that point.
Also, you also really don't want to be creating a new frame/event handler for every call.
Also, even if you fixed the other issues, your function will never return any information about any unit other than "player" or "target" because of this (fixed formatting for readability):
Not sure what you are up to, but I suggest you take a look at "battlegroundtargets".
Thnaks for your answers.
@endx7 , yes you're right the INSPECT_READY event is fired after enemyRole,enemySpec,enemyClass haven't been set
the print returns nil nil nil
then INSPECT_READY is fired
then print correctly the spec of the target
@Phanx the target or player was only written for testing purpose
@Dawn Thanks i'am going to look at this addon
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:
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:
I'm just going to leave here that you don't need that static table to get the spec name.
This should get you there and be dynamic to classes added as long as the API doesn't change significantly.
After you've validated your 'unit' in whatever method to ensure it's one you want to process this snippet will return you the relevant data.
I think based on what you're trying to do, you might also be better served by embedding LibGroupInSpecT-1.0
and letting it handle all the gritty details.
|All times are GMT -6. The time now is 01:05 AM.|
vBulletin © 2016, Jelsoft Enterprises Ltd