Thread Tools Display Modes
12-02-15, 08:12 PM   #1
jadethread
A Murloc Raider
Join Date: Dec 2015
Posts: 4
Need help

Code:
local OnEvent = CreateFrame("Frame") 

OnEvent:SetScript("OnEvent" function(self,event, ...)
		if event == "UNIT_COMBAT" then 
		local unit = select(1,...)
		
		if(unit == "target") then
		combatInitiated(unit);
	  end
 end

 frame:RegisterEvent("UNIT_COMBAT");
 
 
 
function combatInitiated(unit)
                       print("Combat Started With:" ... unit)
end

for some reason my script isnt working I just stared LUA and i was wondering if someone could help me. Basically I wanted to print when combat was started with the unitname. I know unit doesnt return the name of the target but I dont know what Im doing really.
  Reply With Quote
12-02-15, 08:13 PM   #2
Lombra
A Molten Giant
 
Lombra's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 554
Missing a closing parenthesis for SetScript. And an end somewhere, too.
__________________
Grab your sword and fight the Horde!
  Reply With Quote
12-02-15, 08:21 PM   #3
Seerah
Fishing Trainer
 
Seerah's Avatar
WoWInterface Super Mod
Featured
Join Date: Oct 2006
Posts: 10,860
Make sure Lua errors are enabled in your Interface Options.
__________________
"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
12-02-15, 09:09 PM   #4
jadethread
A Murloc Raider
Join Date: Dec 2015
Posts: 4
thank you guys for the reply. gonna work on it now
  Reply With Quote
12-02-15, 09:23 PM   #5
jadethread
A Murloc Raider
Join Date: Dec 2015
Posts: 4
idk whats wrong honestly, will work on it more tomorrow.
  Reply With Quote
12-02-15, 09:29 PM   #6
MunkDev
A Scalebane Royal Guard
 
MunkDev's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2015
Posts: 431
There were plenty of errors in this snippet:
1. Missing an end in the nestled if statement.
2. You confused variable number of arguments (...) with string concatenation (..).
3. Trying to register event on a non-existing frame (your frame is called OnEvent, not "frame").
4. Globally declaring a trivial function. You should localize your code and keep it in the correct order, meaning code that's used later should be declared beforehand.
5. It's pointless to do select(1, ...). Just do "local unit = ..." since that will catch the first argument.
6. You didn't close the SetScript function and you didn't separate "OnEvent" (first argument) from the actual function snippet (second argument).

Lua Code:
  1. local OnEvent = CreateFrame("Frame")
  2.  
  3. local function combatInitiated(unit)
  4.     print("Combat Started With:" .. unit)
  5. end
  6.  
  7.  
  8. OnEvent:SetScript("OnEvent", function(self,event, ...)
  9.     if event == "UNIT_COMBAT" then
  10.         local unit = ...
  11.  
  12.         if unit == "target" then
  13.             combatInitiated(unit)
  14.         end
  15.     end
  16. end)
  17.  
  18. OnEvent:RegisterEvent("UNIT_COMBAT")
__________________

Last edited by MunkDev : 12-02-15 at 09:32 PM.
  Reply With Quote
12-04-15, 10:55 PM   #7
jadethread
A Murloc Raider
Join Date: Dec 2015
Posts: 4
thanks so much ^^ its working now
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » 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