• for loop y u no worky
    8 replies, posted
[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 ;)
Infact it shouldn't have run in the first place, next time check for syntax errors.
[QUOTE=my_hat_stinks;34298205]if ply:HasWeapon( v ) Should be if ply:HasWeapon( v ) then ;)[/QUOTE] I really feel like a derp. I usually never make stupid mistakes like this........ lol oh well. [editline]19th January 2012[/editline] [QUOTE=Wizard of Ass;34298315]Infact it shouldn't have run in the first place, next time check for syntax errors.[/QUOTE] 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 :P
[QUOTE=InfernalCookie;34298065][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.[/QUOTE] 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
[QUOTE=InfernalCookie;34298316]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 :P[/QUOTE] You didn't get a big yellow/blue 'then expected near if at line'?
[QUOTE=InfernalCookie;34298065]Also, this is all in the same function.[/QUOTE] you define the variable "weapons" every time the function runs? should move it outside the function to increase efficiency
[QUOTE=DylanWilson;34306032]you define the variable "weapons" every time the function runs? should move it outside the function to increase efficiency[/QUOTE] The function rarely runs, so it's not a big deal, but I'll take your advice anyways! Thanks!
Sorry, you need to Log In to post a reply to this thread.