I am creating a table of bones and IDs based on bone count. Obviously this is not a proper sequentially listed table. So I have a function that should reorder a table with pairs in alphabetical order.
When I print the table using table.foreach the order goes back to what it was before I reordered it.
I even "copied" the table during reordering to a NEW table and the new table is also "out of order".
This is the function I am using that I found on the web:
Code: Select all
    function pairsByKeys(t, f)
      local a = {}
      for n in pairs(t) do table.insert(a, n) end
      table.sort(a, f)
      local i = 0      -- iterator variable
      local iter = function ()   -- iterator function
        i = i + 1
        if a[i] == nil then return nil
        else return a[i], t[a[i]]
        end
      end
      return iter
    end
Let me rephrase that... I know I am missing something. I understand that tables aren't necessarily in any specific order. How the heck do I create a table in a specific order... or is that not possible? Do I need to run the table sort during what ever final process that needs to be done?
In the examples I've seen a new table created from the new order maintained the order... I may be missing something though.
-vern