dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 15 May 2016 11:23 PM |
local start={ Empty={}; Laundromat = { CleanPants = 100; CleanShirt = 50; Detergent = 25; }; Lobby = { Elevator = 0; }; }
I am using i,v in pairs to get every item in the table and use it for stuff, the problem is that the order of i,v in pairs seems to not care what order I set the table and it is making it hard for me to do stuff with it, to see my problem go here: https://www.roblox.com/games/403644931/WIP the lobby is supposed to be on the bottom but because of the way i,v in pairs works its not grabbing the correct order (I tried manipulating the order I declared the values it didnt work)
|
|
|
| Report Abuse |
|
|
|
| 15 May 2016 11:31 PM |
| Yeah the non-array part of Lua tables have no defined order. |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 15 May 2016 11:31 PM |
is there a way I can order them? lol I need them ordered the order of the floors of this tower
|
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 15 May 2016 11:37 PM |
local t = { { -- [1] Name = "Place1", ., ., ., }, { -- [2] Name = "Place2", ., ., ., } }
change the string keys to indexes and it'll sort them correctly, just set a Name value inside the table (where Name is the old key) or have another array with just the key names sorted correctly and index from the start table based on that order |
|
|
| Report Abuse |
|
|
dave2011
|
  |
| Joined: 02 Oct 2010 |
| Total Posts: 10581 |
|
|
| 15 May 2016 11:45 PM |
^theres no other way? dang that means I have to rewrite a bunch of code, but if that for sure works I guess ill use it
|
|
|
| Report Abuse |
|
|
yankana
|
  |
| Joined: 17 Jun 2011 |
| Total Posts: 431 |
|
|
| 16 May 2016 12:50 AM |
table.concat(Laundromat,", ") -- Gets the table's items in same order seperated by ", ". Example:
CleanPants = 100, CleanShirt = 50, Detergent = 25 |
|
|
| Report Abuse |
|
|
|
| 16 May 2016 06:33 AM |
| Wait I thought i, v in ipairs was different and would go through in an order?? |
|
|
| Report Abuse |
|
|
OzzyFin
|
  |
| Joined: 07 Jun 2011 |
| Total Posts: 3600 |
|
|
| 16 May 2016 06:36 AM |
ipairs only works for arrays
there's an order in arrays because the keys are number indexes |
|
|
| Report Abuse |
|
|
| |
|