Quantcast How to print when target is changed? - WoWInterface
Thread Tools Display Modes
06-14-20, 02:39 PM   #1
sharp230
A Defias Bandit
Join Date: Jun 2020
Posts: 2
How to print when target is changed?

Hello,

I'm a new programmer, and just trying to complete what I thought would be a simple task. I want to print "You've targeted <UnitName>" each time I select a new target. I cannot get this to work. My code is below:

Code:
local UIConfig = CreateFrame("Frame")
UIConfig:RegisterEvent("PLAYER_TARGET_CHANGED")

UIConfig:SetScript("OnEvent",
	function(self, event, ...)
		local arg1 = ...
                print("TEST")
end
I can't even get it to print "TEST" when I target something. If someone could give me a hint, I can figure out the rest, I've just been pulling my hair out for the past two days over this.

Edit: This is for WoW Classic
  Reply With Quote
06-14-20, 02:55 PM   #2
Fizzlemizz
I did that?
 
Fizzlemizz's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Dec 2011
Posts: 1,214
Originally Posted by sharp230 View Post
Hello,

I'm a new programmer, and just trying to complete what I thought would be a simple task. I want to print "You've targeted <UnitName>" each time I select a new target. I cannot get this to work. My code is below:

Code:
local UIConfig = CreateFrame("Frame")
UIConfig:RegisterEvent("PLAYER_TARGET_CHANGED")

UIConfig:SetScript("OnEvent",
	function(self, event, ...)
		local arg1 = ...
                print("TEST")
end
I can't even get it to print "TEST" when I target something. If someone could give me a hint, I can figure out the rest, I've just been pulling my hair out for the past two days over this.

Edit: This is for WoW Classic
If this is all the code then you're probably getting an error because of the missing bracket after the last "end" to close the SetScript call.

Lua Code:
  1. local UIConfig = CreateFrame("Frame")
  2. UIConfig:RegisterEvent("PLAYER_TARGET_CHANGED")
  3.  
  4. UIConfig:SetScript("OnEvent", function(self, event, ...)
  5.     local arg1 = ...
  6.     print("TEST")
  7. end)

Install BugGrabbler and BugSack to help you debug your code.
__________________
Fizzlemizz
Maintainer of Discord Unit Frames and Discord Art.
Author of FauxMazzle, FauxMazzleHUD and Move Pad Plus.

Last edited by Fizzlemizz : 06-14-20 at 03:00 PM.
  Reply With Quote
06-14-20, 03:08 PM   #3
sharp230
A Defias Bandit
Join Date: Jun 2020
Posts: 2
Originally Posted by Fizzlemizz View Post
If this is all the code then you're probably getting an error because of the missing bracket after the last "end" to close the SetScript call.

Lua Code:
  1. local UIConfig = CreateFrame("Frame")
  2. UIConfig:RegisterEvent("PLAYER_TARGET_CHANGED")
  3.  
  4. UIConfig:SetScript("OnEvent", function(self, event, ...)
  5.     local arg1 = ...
  6.     print("TEST")
  7. end)

Install BugGrabbler and BugSack to help you debug your code.
I'm an idiot. That fixed it!! Thank YOU!!
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » How to print when target is changed?

Thread Tools
Display Modes

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