1715 posts
Location
ACDC Town
Posted 10 October 2015 - 08:16 PM
So say there's a table like this:
doop = {
one = "One!",
two = "Tehwoo!",
three = "Tree!",
}
I want to be able to get a table that ends up like this:
doopMethods = seperateMethods(doop)
doopMethods = {
{
"one",
"One!",
},
{
"two",
"Tehwoo!",
},
{
"three",
"Tree!",
},
}
How do I do this?
Edited on 10 October 2015 - 06:35 PM
724 posts
Location
Kinda lost
Posted 10 October 2015 - 08:56 PM
You can achiveve that using
for key,value in pairs(table) do end
loop.
And
table.insert(table,value)
to add stuff to your new table.
In your program case it would be
local function seperateMethods(In)
Out={}
for key,value in pairs(In) do
table.insert(Out,{key,value})
end
return Out
end
In this code the before-mentioned loop is going over the given table using pairs function and placing all keys with their values in 2nd table.
Can i ask why you are changing from 1st table to 2nd? I mean reasoning for it?
Edited on 10 October 2015 - 07:07 PM
1715 posts
Location
ACDC Town
Posted 10 October 2015 - 09:12 PM
Can i ask why you are changing from 1st table to 2nd? I mean reasoning for it?
You mean why I would want to do this? Or why I changed what I wanted halfway? I think the latter.
It's because I realized I needed more information than I originally thought when typing it.
Also, I posted this because I needed help for my STD program.
724 posts
Location
Kinda lost
Posted 10 October 2015 - 09:17 PM
You mean why I would want to do this? Or why I changed what I wanted halfway? I think the latter.
I meant former but i guess you want to just store data in different way that makes sense to you.
51 posts
Posted 12 October 2015 - 10:09 PM
Note that, performance wise, working with what you got is always faster than converting to what you want. Not that Lua is that fast though >.>