AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 24 May 2015 03:51 PM |
Is it possible to do something like this with table.remove (instead of doing the index number like stated on the wiki)
table.remove(VeryLongTable, "value35") -- Searching for this, instead of the index number for 35. |
|
|
| Report Abuse |
|
|
| |
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 24 May 2015 03:52 PM |
| are you asking about custom indices, or about removing based on the value not the index? |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 24 May 2015 03:53 PM |
| Removing based on the value, not index # |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 24 May 2015 03:53 PM |
| because the reason you can't remove based on the value the same way as an index, is because two different values can have the same index. |
|
|
| Report Abuse |
|
|
amanda
|
  |
| Joined: 21 Nov 2006 |
| Total Posts: 5925 |
|
|
| 24 May 2015 03:53 PM |
omg so much typo
two different indices can have the same value |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 03:54 PM |
You can make your own, or use warspyking's module. This is how you would make it your own:
local function RemoveFromTable(table, value) for i, v in pairs(table) do if v == value then table.remove(table, i) end end end
Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784 |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 03:54 PM |
No, this is not possible. You can only use table.remove with numerical indexes.
Example: local tbl={true,false,true,true,false,0,1,1,0,0,1,0,1,1,1,0}; local firstIndex=table.remove(tbl,1); print(firstIndex,tbl[1]);
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 24 May 2015 04:03 PM |
@powerhotmail123 Please let me test you. It's a challange, 90% of all people on this forum won't succeed! Find the error in your script.
If you can't find it pm me or reply to this thread, happy to help you out :) If you can also pm me or reply to this thread.
I wish you the best of luck :)
Don't start to doubt your scripting skills if you can't find it , but it's a pretty simple and stupid error. |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 04:05 PM |
@power
You simply don't avoid table.remove by looping through the table just to use table.remove at the end. That's just silly. |
|
|
| Report Abuse |
|
|
BowtieMod
|
  |
| Joined: 01 Apr 2013 |
| Total Posts: 804 |
|
|
| 24 May 2015 04:06 PM |
table.remove(VeryLongTable, "value35")
what would that even do
associative arrays aren't even ordered
just do t[k] = nil |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 24 May 2015 04:07 PM |
And no it's not this one: " local function RemoveFromT:6: attempt to call field 'remove' (a nil value) " that's just because you named a parameter after a datatype... |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 04:09 PM |
Ermm...
I only made it in 30 seconds lol. I have done it before in a real script.
I think it is because I used 'table'. I should have used something like Tab.
Am I right?
Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784 |
|
|
| Report Abuse |
|
|
AntiFiter
|
  |
| Joined: 14 May 2009 |
| Total Posts: 12290 |
|
|
| 24 May 2015 04:11 PM |
| What's the simplest way to take the table from the module, and create a new one so that I can use table.remove on it without affecting the real table in the module? |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 04:13 PM |
| No, it's because if the value's key is non-numeric then it will break because of the table.remove. Your script doesn't do anything more than what table.remove alone would be able to do. |
|
|
| Report Abuse |
|
|
LucasLua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7386 |
|
|
| 24 May 2015 04:14 PM |
| http://wiki.roblox.com/index.php?title=Cloning_tables |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 24 May 2015 04:14 PM |
I just said it wasn't that one... It's alsno not that roblox parameters aren't passed by reference... |
|
|
| Report Abuse |
|
|
BowtieMod
|
  |
| Joined: 01 Apr 2013 |
| Total Posts: 804 |
|
|
| 24 May 2015 04:15 PM |
there is nothing hard about this
set the reference to nil and the GC will take care of it
VeryLongTable[value35] = nil |
|
|
| Report Abuse |
|
|
BowtieMod
|
  |
| Joined: 01 Apr 2013 |
| Total Posts: 804 |
|
|
| 24 May 2015 04:17 PM |
whoops
VeryLongTable["value35"]
huehuehue |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 24 May 2015 04:17 PM |
@powerhotmail123 Just ignore the other people and try harder. If you can find it, maybe I'll join your group... |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 04:18 PM |
Umm, I just tested the first script I posted, that didn't work. But when I replaces 'table' with 'Tab' it worked. So it does... I also printed the values before and after, and it deleted it. With the exception of when I used 'table' instead of 'Tab', obviously.
Enjoying your stay at the Scripters Forum? Join this! http://www.roblox.com/My/Groups.aspx?gid=2582784 |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 24 May 2015 04:20 PM |
@powerhotmail123 You still can't find it? Think harder. Like I said it's very simple, but a really annoying error... |
|
|
| Report Abuse |
|
|
|
| 24 May 2015 04:21 PM |
| Did you remove any non-numerical indices when you tested it? |
|
|
| Report Abuse |
|
|
eLunate
|
  |
| Joined: 29 Jul 2014 |
| Total Posts: 13268 |
|
|
| 24 May 2015 04:21 PM |
The obvious problem is that table.remove is not the thing he needed because it's not going to work in pairs.
function remove(t,v) for k,n in pairs(t) do if n == v then t[k] = nil; end; end; end; |
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 24 May 2015 04:23 PM |
@powerhotmail123 eLunate has the same error... |
|
|
| Report Abuse |
|
|