Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How would I move a key in a table to a different array?

Asked by 4 years ago
local Tab = {Xd = 'G', ge  = 'g',ce = 'gg',keke = '1', fefe = '2'}


What if I wanted to move Xd to first 
and ge to last 

what would I do?

0
Dictionaries are unordered, so it is impossible to do what you want and get the expected output when you're iterating over it.over it dualworlds 90 — 4y

1 answer

Log in to vote
0
Answered by
ArtBlart 533 Moderation Voter
4 years ago

You can pretty easily reference the values that you wanna put into the other table and just copy em' over. You can do it like so:

local newtbl = {}
local Tab = {Xd = 'G', ge  = 'g',ce = 'gg',keke = '1', fefe = '2'}

newtbl.Xd = Tab.Xd
newtbl.ge = Tab.ge

Or, if you're converting the table into a regular old array, you can use table.insert() and it will automatically insert it for you, in order.

local newtbl = {}
local Tab = {Xd = 'G', ge  = 'g',ce = 'gg',keke = '1', fefe = '2'}

table.insert(newtbl,Tab.Xd)
table.insert(newtbl,Tab.ge)

Hope this helps! If you have any further questions feel free to comment or look things up on the devforum.

1
All you did was make a new table, not actually change the original table Warfaresh0t 414 — 4y
0
the original question was about moving a key to a different table, not rearranging in the same one ArtBlart 533 — 4y
0
yes it is, you just couldn't interpret it dualworlds 90 — 4y
Ad

Answer this question