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: table.remove

Previous Thread :: Next Thread 
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
09 Jul 2014 09:21 AM
How do I remove a specific element from a table without knowing its position in the table and knowing its value?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:23 AM
function getIndex(tab, value)
if type(value) == "string" then value = value:lower() end
for k,v in pairs(tab) do
if type(v) == "string" then v = v:lower() end
if v == value then
return k
end
end
return nil
end
Report Abuse
DragonODeath is not online. DragonODeath
Joined: 02 May 2011
Total Posts: 1252
09 Jul 2014 09:26 AM
D:
Please do explain.
And the element that I want to remove is not a string, it's an instance.
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
09 Jul 2014 09:28 AM
table_remove = function(_table, _value)
for index, value in pairs(_table) do
if value == _value then
table.remove(_table,index)
return true
end
end
return false
end

local t = {1,2,3,"hello"}
table_remove(t,"hello")

should work.


Second poster modifies strings which is stupid for something like this
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:28 AM
tab = {game.Players.Duelingwarlord}

function getIndex(tab, value)
if type(value) == "string" then value = value:lower() end
for k,v in pairs(tab) do
if type(v) == "string" then v = v:lower() end
if v == value then
return k
end
end
return nil
end

table.remove(tab, getIndex(tab, game.Players.Duelingwarlord))
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:30 AM
How would I know what type of table it is.
He tells me after the fact. There is something called reading before you type.
Learn to do that before you throw words around that make you look brainless.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:30 AM
oh and hey you used exactly the same thing I did.
you must be stupid as well :p
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
09 Jul 2014 09:31 AM
I just don't modify the strings.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:32 AM
your point?
Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
09 Jul 2014 09:33 AM
Your script is more stupid than mine.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:36 AM
no urs is, he didn't tell me what type he wanted.
so I assumed strings and not instances.
Mine works for strings AND instances

so me > u

Report Abuse
Trioxide is not online. Trioxide
Joined: 29 Mar 2011
Total Posts: 32902
09 Jul 2014 09:48 AM
Mine supports strings, instances, numbers, booleans ect..
and it doesnt mess up strings.
Report Abuse
COOLDUDE11OO is not online. COOLDUDE11OO
Joined: 21 Aug 2011
Total Posts: 5115
09 Jul 2014 09:52 AM
local get_index=function(t,val)
local index=nil
for i,v in ipairs(t) do
if val:lower()==v:lower() then
index=i
end
end
return index
end

local ex={'Hi','Two',2,1.1,'L','A'}
local index_1=get_index(ex,'Two')
local index_2=get_index(ex,2)
table.remove(ex,index_1)
table.remove(ex,index_2)
print(table.concat(ex,', '))
Report Abuse
WickedSiege is not online. WickedSiege
Joined: 03 Oct 2011
Total Posts: 3039
09 Jul 2014 09:56 AM
Boys, let's not fight over this.
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:57 AM
I can remove 2 lines and it'd be better than yours still.
so why are you so upset?
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 09:59 AM
lol tri is trying so hard 2 be a nerd xdddd
Report Abuse
maxomega3 is not online. maxomega3
Joined: 11 Jun 2010
Total Posts: 10668
09 Jul 2014 10:20 AM
Duel, calm down man. All I see you do is get into arguments on these threads.

Also, what I do is this:

table = {"What", "You", "Had"}

randnum = math.random (1,#table)
table.remove (table,randum)
Report Abuse
Duelingwarlord is not online. Duelingwarlord
Joined: 15 Feb 2010
Total Posts: 22333
09 Jul 2014 11:49 AM
Other people provoke these arguments + you did it wrong.
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