Some questions about Lua

I have read the wiki and other guides but I can’t seem to understand the concept of Functions and Arguments fully.

hook.Add( "PlayerInitialSpawn", "First_Spawn", function( ply )
    ply:PrintMessage( HUD_PRINTTALK, "Welcome to the server " .. ply:GetName() .. "!" );
end );

In this code, I have some questions.
What is (ply) and why is it written in brackets?

( "PlayerInitialSpawn", "First_Spawn", function( ply )

Why are there commas?

I would really appreciate a detailed response about this as I want to understand this and start writing my own code soon.
Thanks :smiley:

Commas are to separate arguments in functions. Hook.add is a function that takes a hook name, an identifier, and a callback function as its arguments, in that order. The ply in parentheses is a variable local to the callback function that is sent to the function when it is called. If you don’t understand these concepts I recommend you check out the lua documentation on functions and arguments

Lua documentation?
Where can I find it?

Arguments are provided data elements which are sent in by the engine or a programmer when they call that function. “ply” is just the name that the programmer made for that example; you can name it anything you want like “Player” or “Whatever,” so long that you change all uses of “ply” in the code. The commas separate arguments when you call a function: hook.Add takes three arguments: a string for the event (PlayerInitialSpawn), a string for the name of the hook – which can be anything you want (First_Spawn), and a callback function for when the event occurs.

[editline]20th October 2015[/editline]

If you don’t want to get the books, check out the reference manual.

Here is the lua reference manual

So basically the ply variable is the player thats spawning first time. What your looking at is a hook. It is called whenever said action happens. So the idea is, if oyu have a player spawning the first time, you have a way to detect it, and when it detects it, it calls the function you defined, giving the ply a actaul value, the player that joined. Sorry if i didnt help i tried my best XD

Thanks everyone for helping me out!