Jump to content

Making a Table of numbers in order


KariiiM

Recommended Posts

Hey guys,

Anyone know a LUA Function that is able to make a list of numbers in order , like 1,2,3,4...

For example, i have a table looking like that:

  
local aTable= { 
{4, "row4"}, 
{2, "row2"}, 
{1, "row1"}, 
{3, "row3"}, 
} 

and after using this function it should be in order like this example below: (im sure there's a lua function for that just i didn't search well)

  
local aTable= { 
{1, "row1"}, 
{2, "row2"}, 
{3, "row3"}, 
{4, "row4"}, 
} 

Link to comment

Do the integers have any specific meaning, or does it just act as an ID for the row? If so, you could do this;

local aTable = { 
    [4] = "row4", 
    [2] = "row2", 
    [1] = "row1", 
    [3] = "row3", 
} 
  
table.sort(aTable) 
  
for i=1, 4 do 
    print(aTable[i]) 
end 

I suggest you use a website such as repl.it and you can try things like these directly in your browser. :)

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...