Thread Tools Display Modes
03-14-09, 10:28 AM   #1
gam35guru
A Defias Bandit
Join Date: Mar 2009
Posts: 2
Unhappy PLAYER_TARGET_CHANGED need help

Hey guys,

You're prolly all gonna see me crying my butt off in the forums over the next couple of weeks/month since I made a very silly decision to make a wow addon for my final year project of my degree =S

First off I've followed the tutorials, learnt about registering events etc, but the problem Im having with the PLAYER_TARGET_CHANGED event is this:

I want to detect when targetchanges and then update the name of the new target, however when there is NO target, I get a "attempted to concatenate a nil value" error as there targets name doesnt exist cos I DONT GOTTA TARGET =S

D'oH!

Now I know what I must do, check to see if the player currently has a target, if I do **Do SOMETHING HERE** .... but if I don't.... end...... trouble is, I dont know hwo to determine that.

Im having a real pain in the ass trying to find a little tutorial on variable creation/management and variable types..... I don't know what the valid types are for when it comes to creating variables for my addon.

I would need a variable to detect currentTarget and LastTarget so I could update them and when the PLAYER_TARGET_CHANGED event is detected, I would check if currentTarget == nil, then just dont process it.

It's really got me stumped guys and Im only at the first hurdle.... please can anyone help?

Muchos Love
gam35guru
  Reply With Quote
03-14-09, 11:20 AM   #2
gam35guru
A Defias Bandit
Join Date: Mar 2009
Posts: 2
Lightbulb Fixed it!

Something so bloody simple ... but I didnt know what I had to check against.... this is how I solved it for anyone who gets stuck like I did....

if ( UnitName("target") == nil ) then
FontString2:SetText( "<< No Target Guvner >>" );
else
FontString2:SetText( "Target: " .. UnitName("target") .. "!" );
end


Id still like a response with regards to the variable types that can be used in wow addon creation.... or is it all just one global variable type.... for example, no difference between a variable that holds a string or an int, or a float....

Thanks Guys
gam35guru

PS. Persistence pays off ^^

Also, if any addon guru would like to make a few pounds/euros/dollars (whatever ur currency) assisting with creation/debugging of my ickle project, I'll be happy to throw some cash your way for some navigation in the right direction with whatever I get stuck with! <3 <3 <3

Leave your response here, I'll check back and send personal messages with contact info. Only people with strong english spoken need respond.... I dont speak any other language unfortunately =S
  Reply With Quote
03-14-09, 11:25 AM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
http://www.lua.org/pil/
http://lua-users.org/wiki/TutorialDirectory
http://www.wowwiki.com/Main_Page
http://www.wowprogramming.com/
__________________
"You'd be surprised how many people violate this simple principle every day of their lives and try to fit square pegs into round holes, ignoring the clear reality that Things Are As They Are." -Benjamin Hoff, The Tao of Pooh

  Reply With Quote
03-14-09, 04:59 PM   #4
Torhal
A Pyroguard Emberseer
 
Torhal's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2008
Posts: 1,196
I won't go into detail about types and such, as the links Seerah gave will tell you all you need to know.

As to your code - there's a more concise way of going about it which is also a bit more efficient, since you're not calling UnitName() twice:

Code:
local unit_name = UnitName("target") or "None"

FontString2:SetText( "Target: "..unit_name.."!" );
__________________
Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Author of NPCScan and many other AddOns.
  Reply With Quote
03-14-09, 09:49 PM   #5
Soulsbane
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 7
You can also use UnitExists("target") to check if you have a target selected since that event your using also fires when you deselect a unit.
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » PLAYER_TARGET_CHANGED need help


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