generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: i,v in pairs

Previous Thread :: Next Thread 
dave2011 is not online. 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
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
15 May 2016 11:31 PM
Yeah the non-array part of Lua tables have no defined order.
Report Abuse
dave2011 is not online. 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 is not online. 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 is not online. 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 is not online. 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
Andyliu5000 is not online. Andyliu5000
Joined: 02 Nov 2013
Total Posts: 969
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 is not online. 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
Andyliu5000 is not online. Andyliu5000
Joined: 02 Nov 2013
Total Posts: 969
16 May 2016 06:40 AM
Thanks!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image