[QUOTE=Teddi Orange;29049842][b][url=http://wiki.garrysmod.com/?title=Table.remove]Table.remove [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b][/QUOTE]
No. He's asking about removing by value, not by key.
[lua]for k, v in pairs( tbl ) do
if v == value then
tbl[k] = nil
end
end[/lua]
[QUOTE=raBBish;29050434]No. He's asking about removing by value, not by key.
[lua]for k, v in pairs( tbl ) do
if v == value then
tbl[k] = nil
end
end[/lua][/QUOTE]
[b][url=http://wiki.garrysmod.com/?title=Table.KeyFromValue]Table.KeyFromValue [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] is a shortcut for looping through the table.
[QUOTE=PortalGod;29056865][b][url=http://wiki.garrysmod.com/?title=Table.KeyFromValue]Table.KeyFromValue [img_thumb]http://wiki.garrysmod.com/favicon.ico[/img_thumb][/url][/b] is a shortcut for looping through the table.[/QUOTE]
That would work if he only wanted to remove only one of the specific value, I assumed he wanted to remove every element with the value.
Just one, actually, but thanks for the help. Its for an inventory script, so I can use what is returned by that in table.remove.
Sorry, you need to Log In to post a reply to this thread.