for loop y u no worky

[lua]
local weapons = { “weapon_zm_rifle”,
“weapon_ttt_awp”,
“etc.”
}

for k, v in pairs( weapons ) do
if ply:HasWeapon( v )
ply:StripWeapon( v )
end
end
[/lua]
Anyone know why this doesn’t work??? I’m so lost… P.S. “ply” IS being defined, no worries. Also, this is all in the same function.

Are there any errors?

if ply:HasWeapon( v )

Should be

if ply:HasWeapon( v ) then

:wink:

Infact it shouldn’t have run in the first place, next time check for syntax errors.

I really feel like a derp. I usually never make stupid mistakes like this… lol oh well.

[editline]19th January 2012[/editline]

Don’t worry Wizard, I already have a function that I’ve made sure that runs, it was the loop I made that didn’t work :stuck_out_tongue:

Also since you’re not using k, you should name it _. Just good practice to increase readability.

EDIT: BUT CHESSNUT IT MAKES YOUR CODE FASTER, JUST LIKE APPENDING ; AFTER EVERY LINE

You didn’t get a big yellow/blue ‘then expected near if at line’?

you define the variable “weapons” every time the function runs? should move it outside the function to increase efficiency

The function rarely runs, so it’s not a big deal, but I’ll take your advice anyways! Thanks!