generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: Is there any way to remove an object from a table

Previous Thread :: Next Thread 
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
17 Jul 2014 11:12 PM
if you know the name and not the place?

table.remove () requires the place in the table as the second argument, but I don't know it. I just know the name.
Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
17 Jul 2014 11:13 PM
for n,v in pairs(tbl) do
if v == "name" then
table.remove(tbl, n)
break
end
end
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
17 Jul 2014 11:19 PM
Thanks.
Report Abuse
KEVEKEV77 is not online. KEVEKEV77
Joined: 12 Mar 2009
Total Posts: 6961
17 Jul 2014 11:19 PM
Roy, actually, it would change and remove the wrong things(I think).

tbl={}
tbl2={}
for n,v in pairs(tbl) do
if n == "NAME" then
table.insert(tbl2, n);--Actually this might result in the same way.
end
end
tb2 = {}


Report Abuse
RoyStanford is not online. RoyStanford
Joined: 21 Oct 2008
Total Posts: 2222
18 Jul 2014 12:09 AM
No, KEV, it wouldn't. I break the loop after I remove the single value.
Report Abuse
veryveryveryhidden is not online. veryveryveryhidden
Joined: 16 Dec 2012
Total Posts: 486
18 Jul 2014 12:32 AM
tab[name]=nil
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
18 Jul 2014 09:22 AM
@Very, the only problem with that is that the object is a team and setting it to nil would destroy the team or possibly still be in the table just as a nil value.

The first poster's solution work like a charm. Thanks.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
18 Jul 2014 09:28 AM
@Max

Remember my plugin TULOF (The Ultimate List Of Functions)?

You should have checked that. I'm writing from memory but this was part of it;

function Table_Destroy(T, V)
for I,v in pairs(T) do
if v == V then
table.remove(T, I)
end
end
end
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
18 Jul 2014 06:07 PM
I have yet to install it.

Ehh, I'll probz need it.
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
18 Jul 2014 07:13 PM
XD

It only has a few functions. I haven't been around to updating it.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
18 Jul 2014 07:19 PM
local table_remove=function(tab,val)
for i=1,#tab do
if tab[i]==val then
table.remove(tab,i)
break
end
end
end
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
18 Jul 2014 11:40 PM
Oh, you forgot a break in that loop, war.
#rekt

I really wasn't expecting this thread to last that long...
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
19 Jul 2014 06:41 AM
I didn't forget the break. If you want a value gone from the table, why would you just remove the first one, and who's to say you wanted the FIRST one removed hmm? So for safety measures I removed them all.
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
19 Jul 2014 09:38 PM
what
wow, what a loophole.

Next time I'll get ya, ya ol' coot!
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
19 Jul 2014 10:10 PM
@War
Yours doesn't work

function Table_Destroy(T, V)
for I,v in pairs(T) do
if v == V then
table.remove(T, I)
end
end
end

local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi"}
Table_Destroy(t, "Hello")
print(unpack(t))

Output:Hello Hey Hi Hi







function rft(...)
local t, v, s = unpack({...})
local s, S = (s == nil and math.huge or s), 0
local quarantine = {}
for I, V in pairs (t) do
if V == v and s > S then
S = S + 1
table.insert(quarantine, I)
end
end
for q = #quarantine, 1, -1 do
table.remove(t, quarantine[q])
end
return #quarantine
end

local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi"}
rft(t, "Hello") --removes all
print(unpack(t))

--[[Output
Hey Hi Hi]]



local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi"}
rft(t, "Hello", 2) --removes only the first 2
print(unpack(t))

--[[Output
Hey Hello Hi Hi]]
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
19 Jul 2014 10:12 PM
tulof is dumb
Report Abuse
warspyking is not online. warspyking
Joined: 15 Nov 2011
Total Posts: 13947
20 Jul 2014 06:52 AM
Okay, here you go then.

function table_destroy(T, v)
local X = 1
repeat
if T[X] = v then
table.remove(T, X)
else
X = X + 1
end
until X == #T --Note; Will not work with dictionaries. See NumItems
end



function NumItems(T)
local n = 0
for I,v in pairs(T) do
n = n + 1
end
return n
end


--^Use that for dictionaries.
Report Abuse
UncleTaz is not online. UncleTaz
Joined: 19 Aug 2009
Total Posts: 12795
20 Jul 2014 07:04 AM
Wow. All that just removing a object from table.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
20 Jul 2014 08:46 AM
item[object] = nil

easy 4 dictionaries
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
20 Jul 2014 09:19 AM
@War
Still doesn't work


function table_destroy(T, v)
local X = 1
repeat
if T[X] == v then
table.remove(T, X)
else
X = X + 1
end
until X == #T --Note; Will not work with dictionaries. See NumItems
end


local t = {"Hello", "Hello", "Hey", "Hello", "Hi", "Hi", "Hello"}
table_destroy(t, "Hello")
print(unpack(t))


Output Hey Hi Hi Hello
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image