xScatta Posted January 6, 2014 Posted January 6, 2014 Hey all i have a question. So i put things in table like that table = {vehicle, player1, vehicle8, player9} -- so i want to do something LIKE that table.remove(table,vehicle8) -- btw theres so many things in table this is only example And i don't know how to make something like this BUT working. Anyone help please. Or if it is possible to GET position of element in table.
Castillo Posted January 6, 2014 Posted January 6, 2014 table.remove uses table index, so instead of 'vehicle8' you would need to use '3'.
csiguusz Posted January 6, 2014 Posted January 6, 2014 table.remove uses table index, so instead of 'vehicle8' you would need to use '3'. But if you don't know the index of the value you want to remove, then loop through the table to find it. (note: if you use "table" as a variable name it overwrites the global "table", so you can't use table.remove and other table functions.) for i, v in ipairs ( t ) do if v == vehicle8 then table.remove ( t, i ) end end
Castillo Posted January 6, 2014 Posted January 6, 2014 You can also store the index in another table to avoid looping.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now