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 » Scripters
Home Search
 

Re: An easier function than table.remove()

Previous Thread :: Next Thread 
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
24 Dec 2013 02:55 PM
--
function table_remove(tabl, str)
for i = 1, #tabl do
if tabl[i] == str then
table.remove(tabl, i)
end
end
end
--

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
CoolioTree is not online. CoolioTree
Joined: 26 Dec 2012
Total Posts: 2509
24 Dec 2013 02:56 PM
Coolio
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
24 Dec 2013 02:58 PM
Example of use
--
t = {"Person", "Person2", "Person3"}
table_remove(t, "Person3")
print(unpack(t))
--
>Person Person2

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Dec 2013 03:00 PM
You would probably want to break it after it removes it otherwise it will remove all values with the same name
Report Abuse
CoolioTree is not online. CoolioTree
Joined: 26 Dec 2012
Total Posts: 2509
24 Dec 2013 03:00 PM
Coolio.
Report Abuse
Decompiler is not online. Decompiler
Joined: 30 Aug 2012
Total Posts: 1453
24 Dec 2013 03:02 PM
You could specify the number of times the string will be removed as a third argument, so if you only wanted to remove 1 then you can say so.
Report Abuse
Eternalfireeater is not online. Eternalfireeater
Joined: 01 May 2011
Total Posts: 10027
24 Dec 2013 03:03 PM
--
function table_remove(tabl, str)
for i = 1, #tabl do
if tabl[i] == str then
table.remove(tabl, i)
break
end
end
end
--
Happy, cnt?

~ℇℸℇℛηαℒℱίℛℇℇαℸℇℛ~
Report Abuse
Decompiler is not online. Decompiler
Joined: 30 Aug 2012
Total Posts: 1453
24 Dec 2013 03:05 PM
function table_remove(tabl, str, count)
for i = 1, #tabl do
if tabl[i] == str and count > 0 then
table.remove(tabl, i)
count = count - 1
if count == 0 then -- Optional if statement for very large tables
break
end
end
end
end
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
24 Dec 2013 03:05 PM
nu
Report Abuse
OneTrueGodTheHolyCow is not online. OneTrueGodTheHolyCow
Joined: 24 Oct 2013
Total Posts: 9350
24 Dec 2013 03:13 PM
LOL ARE YOU SERIOUS
Report Abuse
CoolioTree is not online. CoolioTree
Joined: 26 Dec 2012
Total Posts: 2509
24 Dec 2013 03:15 PM
?
Report Abuse
HaxHelper is not online. HaxHelper
Joined: 19 Dec 2009
Total Posts: 1208
24 Dec 2013 04:05 PM
is this what the scripter forum has turned into
Report Abuse
evolvedpikachu is not online. evolvedpikachu
Joined: 18 Aug 2010
Total Posts: 10696
24 Dec 2013 04:06 PM
Table[key] = nil


baboom
Report Abuse
Fluffmiceter is not online. Fluffmiceter
Joined: 28 Jan 2012
Total Posts: 6931
24 Dec 2013 05:39 PM
Why not keep all the values and declare the unused values nil?
Report Abuse
xXxMoNkEyMaNxXx is not online. xXxMoNkEyMaNxXx
Joined: 03 Oct 2008
Total Posts: 3120
24 Dec 2013 05:45 PM
This function will not have the desired behaviour when two matches are adjacent. The table has to be iterated in reverse when items are being removed during the iteration.
Report Abuse
mew903 is not online. mew903
Joined: 03 Aug 2008
Total Posts: 22071
24 Dec 2013 08:02 PM
I think using table.remove is just easier.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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