Jump to content

deleting something from table


John Smith

Recommended Posts

yes its an element, i also tried putting strings in the table,everything on runcode as well and it just wouldnt remove it from table(checked by unpack function)

here an easy working example

  
randomTable = {} 
a = "i need to get removed from a table seriously" 
table.insert(randomTable,a) 
-- its inserted  
  
randomTable[a] = nil 
-- should remove it but doesn't for me. 
  

Edited by Guest
Link to comment

but if i have thousands of things in my table, how can i find out which "ID" is the thing which i want to remove?

also how come other scripts can use the above method with source like mine?

i saw freeroam lots of times using

playerBlips[source] = nil 

and it worked for them -- well, something like this.

Edited by Guest
Link to comment
playersTable[source] = nil 

^ works only when you used something like this before:

playersTable[source] = true 

If you have an indexed table, as Solidsnake14 pointed out, you have to remove that only by its position in the table.

If you want to communicate with the table by the elements and not by IDs, you could better use the way of playersTable[source] = true.

In other cases, you can loop through the table and remove the required position:

for i,v in ipairs(playersTable) do 
  if source == v then -- if there is such element 
    table.remove(playersTable,i) -- remove it from the table according to its index 
  end 
end 

^ this way is not really recommended, but works in case you want to know how it is made.

Link to comment

hello i am a bit confused

something = {} 
something[#something+1] = {playerElement} 
something[#something+1] = {"text","another text",someVariable} 
  

so how would i find an exact thing that i want to delete? how would i know the id of thing to remove?

looping through it wouldnt help as in gallardo's example it would need to be v[1][1] for example at line 2

if anyone can help me please do

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...