View Single Post
11-03-10, 03:17 PM   #12
TransformedBG
A Fallenroot Satyr
Join Date: Oct 2010
Posts: 23
Originally Posted by Dridzt View Post
... is a special variable name that holds an indefinite number of parameters.

It's called a vararg (variable arguments)

When you don't know how many params will be passed to a function
(OnEvent is a prime example as different events pass a different number of arguments)
you can use a vararg to catch them all.

To assign the individual arguments to variables you can just do:
local arg1, arg2, arg3, argX = ...
inside the function.
If you want to know the number of arguments in the vararg
local args = select("#",...) will give you that.

Aww okay i wasnt quite sure..


Have another question rather than make a new thread.

I want to extend my function to something that would tell a guildie who logs on hello. im thinking it would look something like this?

Code:
function GuildLevelUp.OnEvent(self, event, ...)
	local lvl = UnitLevel("player");
	local race = UnitClass("player");
        local playerOn = ? -- what function would i call?
	if ( (event == "PLAYER_LEVEL_UP") ) then
		SendChatMessage("DING! Yeah thats right im now a level "..lvl.." "..race..".", "GUILD", nil, nil);
	elseif ( (event =="PLAYER_ENTERING_WORLD") then
		SendChatMessage("Hello "...playerOn..."! Nice to see you on today!", "GUILD", nil, nil);
		
		else
	
	end
end
I know i would need to change the OnLoad to something different. I belive it would be something like:

Code:
function GuildLevelUp.OnLoad(self) -- Loads on player login --
	self:RegisterEvent("PLAYER_LEVEL_UP");
	self:RegisterEvent("PLAYER_LOGIN");
	self:RegisterEvent("CHAT_MSG_GUILD_ACHIEVEMENT"); -- this would be later if someone got an achievement -- 

	DEFAULT_CHAT_FRAME:AddMessage("[Scare Bears INC] Guild Level Up Announcer has been initialized!");
	DEFAULT_CHAT_FRAME:AddMessage(" Ver. 1.0.0.11");
	DEFAULT_CHAT_FRAME:AddMessage(" Currently there are no /commands.");
end
I know that you pass in "self" being an event that happens to you, but how do you pass an arg that happens in guild? im not sure on that.
  Reply With Quote