Thread Tools Display Modes
09-04-08, 08:23 AM   #1
dragonclaw7000
A Deviate Faerie Dragon
 
dragonclaw7000's Avatar
Join Date: Oct 2006
Posts: 13
Wink Noob needing advice

Ok. I have been coding away on my first addon for a while now and yesterday I ran into an iritating problem. After many hours of trail and error I have yet to find the error. Someone with a little more knowledge who would like to take a look at my code?

This is the part where the error is located:

Code:
function TrapTimer:EventHandler(actionframe, event, ...)
	if event == "PLAYER_ENTERING_WORLD" then
		TrapTimer:Initialize()
	end
	if event == "UNIT_SPELLCAST_SUCCEEDED" then
		ChatFrame1:AddMessage("YEz!")
		local arg1, arg2, arg3 = ...
		TrapTimer:UpdateCooldown(arg1, arg2, arg3)
	end
end

local frame = CreateFrame("Frame", "TrapTimerFrame", UIParent)

frame:RegisterEvent("PLAYER_ENTERING_WORLD")
frame:SetScript("OnEvent", TrapTimer:EventHandler(self, event, ...))

TrapTimer.frame = frame
  Reply With Quote
09-04-08, 08:51 AM   #2
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Code:
frame:SetScript("OnEvent", TrapTimer:EventHandler(self, event, ...))
Is wrong.

I'm guessing you intended to do:
Code:
frame:SetScript("OnEvent", function(self, ...) self:EventHandler(...) end)
but this would work exactly the same without creating another function
Code:
frame:SetScript("OnEvent", TrapTimer.EventHandler)
also you seem to be passing the same argument twice in TrapTimer:EventHandler() as actionframe and self are the same thing.

Basically
Code:
TrapTimer.EventHandler(self)
   blah
end
is the same as
Code:
TrapTimer:EventHandler()
   blah
end
  Reply With Quote
09-04-08, 09:28 AM   #3
dragonclaw7000
A Deviate Faerie Dragon
 
dragonclaw7000's Avatar
Join Date: Oct 2006
Posts: 13
Thanks a lot Works like a charm. ThoughI would like some clarification how to transfer variables from one function to another. This do not give any errors but it won't work:

The idea is to transfer the values of the event arguments to the UpdateCooldown function.

Code:
function TrapTimer:UpdateCooldown(spell_caster, spell_name, spell_rank)
	if spell_caster == "player" then
		if spell_name == "Holy Light" then
			TrapTimer.bar2:SetValue(0)
		end
	end
end

function TrapTimer:EventHandler(...)
	if event == "PLAYER_ENTERING_WORLD" then
		TrapTimer:Initialize()
	end
	if event == "UNIT_SPELLCAST_SUCCEEDED" then
		ChatFrame1:AddMessage("YEz!")
		local arg1, arg2, arg3 = ...
		TrapTimer:UpdateCooldown(arg1, arg2, arg3)
	end
end
  Reply With Quote
09-04-08, 09:36 AM   #4
slizen
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: Jul 2008
Posts: 15
Remove the
Code:
local arg1, arg2, arg3 = ...
and it should work. The arg1,arg2 and arg3 will be set even without the above code.
  Reply With Quote
09-04-08, 09:41 AM   #5
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
Originally Posted by dragonclaw7000 View Post
Thanks a lot Works like a charm. ThoughI would like some clarification how to transfer variables from one function to another. This do not give any errors but it won't work:

The idea is to transfer the values of the event arguments to the UpdateCooldown function.

Code:
function TrapTimer:UpdateCooldown(spell_caster, spell_name, spell_rank)
	if spell_caster == "player" then
		if spell_name == "Holy Light" then
			TrapTimer.bar2:SetValue(0)
		end
	end
end

function TrapTimer:EventHandler(...)
	if event == "PLAYER_ENTERING_WORLD" then
		TrapTimer:Initialize()
	end
	if event == "UNIT_SPELLCAST_SUCCEEDED" then
		ChatFrame1:AddMessage("YEz!")
		local arg1, arg2, arg3 = ...
		TrapTimer:UpdateCooldown(arg1, arg2, arg3)
	end
end

in you TrapTimer:EventHandler() I would pass "event" by changing it too:
Code:
function TrapTimer:EventHandler(event, ...)
instead of doing
Code:
		local arg1, arg2, arg3 = ...
		TrapTimer:UpdateCooldown(arg1, arg2, arg3)
you could instead pass the vararg (...) to TrapTimer:UpdateCooldown().

so
Code:
TrapTimer:UpdateCooldown(...)
or you could create an upvalue of arg1, arg2 and arg3 and pass them to TrapTimer:UpdateCooldown()

Code:
TrapTimer:EventHandler(event, arg1, arg2, arg3)
   blah
   TrapTimer:UpdateCooldown(arg1, arg2, arg3)
end
as a final note the method notation automatically passes the variable "self" which is the same as the table holding the function.

Last edited by Slakah : 09-04-08 at 09:44 AM.
  Reply With Quote
09-04-08, 09:54 AM   #6
dragonclaw7000
A Deviate Faerie Dragon
 
dragonclaw7000's Avatar
Join Date: Oct 2006
Posts: 13
Thanks a lot for the quick replies. Works perfect
  Reply With Quote
09-04-08, 10:08 AM   #7
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Also keep in mind that global arguments are removed in 3.0
  Reply With Quote
09-04-08, 11:29 AM   #8
dragonclaw7000
A Deviate Faerie Dragon
 
dragonclaw7000's Avatar
Join Date: Oct 2006
Posts: 13
So what difference will that bring to the code :?
  Reply With Quote
09-04-08, 11:34 AM   #9
Duugu
Premium Member
 
Duugu's Avatar
AddOn Author - Click to view addons
Join Date: Nov 2006
Posts: 851
None ............
  Reply With Quote
09-04-08, 11:39 AM   #10
p3lim
A Pyroguard Emberseer
 
p3lim's Avatar
AddOn Author - Click to view addons
Join Date: Feb 2007
Posts: 1,710
Just that you have to use
Code:
local arg1, arg2, arg3 = ...
or include the arguments right off


also, you cannot use 'event' without having it set as an argument, same goes for self.
  Reply With Quote
09-04-08, 12:29 PM   #11
dragonclaw7000
A Deviate Faerie Dragon
 
dragonclaw7000's Avatar
Join Date: Oct 2006
Posts: 13
Ok Good to know
  Reply With Quote
09-04-08, 12:47 PM   #12
Slakah
A Molten Giant
 
Slakah's Avatar
AddOn Author - Click to view addons
Join Date: Aug 2007
Posts: 863
also, you cannot use 'event' without having it set as an argument, same goes for self.
unless you use the method notation.
  Reply With Quote

WoWInterface » Developer Discussions » Lua/XML Help » Noob needing advice


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