First lua questions: NOOB questions!

Hey facepunch! I am finally going to start learning some lua! I am trying to create a small gamemode sort of like GTA. I am having trouble doing the slightest of things, and it is getting annoying. Can you please check this snippet of code to see if anything is wrong? ( I know its wrong)

Code for adding stars when someone gets damaged:

function GM:EntityTakeDamage(ent, inflictor, attacker, amount, dmginfo)
	if ent:IsPlayer() and attacker:IsPlayer() then

Help a noob out? I am still confused about how k, v in pairs works, can you help me out!?

for k, v in pairs is a for loop, it loops through whatever you tell it to checking each entity basically, and as far as your code goes AddStars is not even real lua.

Well have you made a meta table for the player and made the :AddStars() function? because other then that i don’t see anything wrong with the code. as for k, v k is like the current number in the table of objects returned and v is the object.

Well yes, I did add the :AddStars() function in another part of the code.

One thing i could see being bad though is that your code has nothing to check the amount of damage so something that 1 shot people would still only get them 1 star but a smg would get a star every time it hit the person.

v is a nil value, you need to replace it with the variable holding the player object you want to add the stars to (ent or attacker).

[editline]17th January 2011[/editline]

pairs is a function for use with the generic for (for in loop). It returns a function that, when called, returns the next key-value pair in a table.