|
| 30 Nov 2016 06:50 PM |
| Get a bunch of tables that have tables inside of that table and put them all into 1 table? (so I can compare 1 table instead of multidimensional tables) Because when I try to sort these tables it doesn't sort all of them it only sorts each table if that somewhat makes sense. e.g: local Table = { --examples table: 2C1EF222 table: 2C1EF223 table: 2C1EF224 } I tried this: table.sort(Table, function(New, Old) return New[3] > Old[3] end) --of course this would work if it was all one table --> ## # # # # # 15 14 13 12 11 10 25 24 23 22 21 20 |
|
|
| Report Abuse |
|
|
| |
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 30 Nov 2016 07:03 PM |
"Get a bunch of tables that have tables inside of that table and put them all into 1 table"
Jesus, you lost me there. |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 30 Nov 2016 07:08 PM |
He means nested tables. Use your brain before you assume you don't understand lol.
He wants to take something like this: { {a,b} , {c,d} , {e,f} }
and turn it into this: {a,b,c,d,e,f}
So he can sort all of the elements with respect to each other instead of just within each subtable.
I'm too tired to work on this problem tonight but I'm sure someone else here will be able to help.
|
|
|
| Report Abuse |
|
|
Ryuzoji
|
  |
| Joined: 21 Dec 2015 |
| Total Posts: 937 |
|
|
| 30 Nov 2016 07:09 PM |
| I understand after your reply, but the lack of "sentence structure" threw me off. Sorry OP. |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 07:12 PM |
| I've been trying everything since last night to get this to work, nothing has worked for me. I've googled stuff and tried it out and it's really hard because I've never iterated through tables like this. |
|
|
| Report Abuse |
|
|
| |
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 30 Nov 2016 07:25 PM |
I'm very tired so I'm not liable if any of this is incorrect.
How deep is your nesting? Are you working with just two-dimensional tables? The first way to do this that comes to mind involves iterating through each table and just doing table.Insert(bigTable, element) for each element in each subtable.
If your structure is guaranteed to be something like: mainTable = { SubTable1 = {a,b}, SubTable2 = {c,d}, SubTable3 = {e,f} }
Then you could probably get away with just a nested for loop:
bigTable = {}
for i,sub in pairs(mainTable) do for j = 1, #sub do table.Insert(bigTable, sub[j]) end end
Of course if your tables are messy or are more than two levels deep it'll be a bit more involved, requiring you to iterate through all children of mainTable, add a child to bigTable if it's a value, or call the function recursively on the child if it's another table.
|
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 07:44 PM |
It's something like this:
[ { "test", "sample", 1, }, { "test2", "sample2", 2, }, ]
I'm not sure of the term, would this still be consider "nesting". |
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 07:44 PM |
| the '[' & ']' brackets are just examples of how I'm trying to explain this |
|
|
| Report Abuse |
|
|
qqtt991
|
  |
| Joined: 14 Dec 2007 |
| Total Posts: 1387 |
|
|
| 30 Nov 2016 07:56 PM |
Whether you have multiple tables, {}, {}, {}, or a table that contains nested tables, { {}, {}, {} }, the principle of what I've written remains the same. You need to go through each table one element at a time and insert each element into the table you intent to use to sort all items.
|
|
|
| Report Abuse |
|
|
|
| 30 Nov 2016 07:57 PM |
| Okay I'll try, thanks for helping even though you are super tired |
|
|
| Report Abuse |
|
|