Why does this not work?

I found this code on a old thread because I’m too damn lazy, I looked through it and it looks fine.

I go onto singleplayer and use a command to test this and get this error:



[ERROR] addons/rp points/lua/colorchat.lua:12: attempt to index global 'arg' (a nil value)
  1. AddText - addons/rp points/lua/colorchat.lua:12
   2. v - addons/rp points/lua/commands.lua:54
    3. unknown - lua/includes/modules/hook.lua:82



I have included colorchat.lua in my commands.lua

This is the code:


if SERVER then
	chat = { }
	function chat.AddText( ... )
		if ( type( arg[1] ) == "Player" ) then ply = arg[1] end
		
		umsg.Start( "AddText", ply )
			umsg.Short( #arg )
			for _, v in pairs( arg ) do
				if ( type( v ) == "string" ) then
					umsg.String( v )
				elseif ( type ( v ) == "table" ) then
					umsg.Short( v.r )
					umsg.Short( v.g )
					umsg.Short( v.b )
					umsg.Short( v.a )
				end
			end
		umsg.End( )
	end
else
	usermessage.Hook( "AddText", function( um )
		local argc = um:ReadShort( )
		local args = { }
		for i = 1, argc / 2, 1 do
			table.insert( args, Color( um:ReadShort( ), um:ReadShort( ), um:ReadShort( ), um:ReadShort( ) ) )
			table.insert( args, um:ReadString( ) )
		end
		
		chat.AddText( unpack( args ) )
	end )
end

Please can someone help me?

Resources I’m using:

http://forum.facepunch.com/showthread.php?t=768062

Depend how you call it but the problem is arg is not set

You never defined “arg”, just like what the error says (attempt to index global “arg”).

[editline]14th July 2013[/editline]

No, what he should add is:



arg = { ... }


Because chat.AddText accepts a vararg (several arguments).

Yer I edited my post but yer it depends how you call it
I usually put all variable names