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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripters
Home Search
 

Re: Table Formatting

Previous Thread :: Next Thread 
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:08 AM
I got a table with a list of all the planets as keys. And I need the following function to find and read the sun first. How would I make it prioritize the sun?
local OurSystem = {
Sun = nil
Mercury= nil
Venus= nil
Earth= nil
Mars= nil
Jupiter=nil
Saturn=nil
Uranus=nil
Neptune=nil
}
function Solar(tarble)
for key, value in pairs(tarble) do
print(key)
end
end
Solar(OurSystem)

Output:Sun Neptune Venus Saturn Uranus Mercury Jupiter Earth
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:12 AM
sorry, the Output says: Mars Sun Neptune Venus Saturn Uranus Mercury Jupiter Earth
Report Abuse
AggressiveCatch is not online. AggressiveCatch
Joined: 17 Jul 2011
Total Posts: 5840
29 Jan 2017 09:14 AM
make another table with only values and not like a dictionary and use that table for the order
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
29 Jan 2017 09:14 AM
Dictionaries have no order.

Also, that isn't valid table syntax.


Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:16 AM
I just replaced what the keys variables are with nil. They actually hold information that I need.
Report Abuse
ChiefDays is not online. ChiefDays
Joined: 26 Sep 2016
Total Posts: 502
29 Jan 2017 09:16 AM
You should make a table like this:

local SolarSystem = {
{"Sun", nil},
{"Mercury", nil}
--bla bla bla
}

for i,v in pairs(SolarSystem) do
print(v[1])
end


Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:21 AM
I was kinda using an array more. And my array contains tables. So like Sun = {Var,Var,Var,Var,Var}. My script depends on the sun existing before the other keys. So is there any workaround I could use?
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
29 Jan 2017 09:26 AM
{
{"Sun", {Var,Var,Var,Var,Var}},
...
}


Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:26 AM
What if I were to do something like this?:
function Solar(tarble)
for i=1, #tarble do
print(tarble[i])
end
end
Although when I try it nothing prints I think something like this could work.
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:27 AM
@chimmihc I'm trying to create a way for me to save/load multiple solar systems. If I were to do each individual planet and sun it would take me a very long time.
Report Abuse
chimmihc is not online. chimmihc
Joined: 01 Sep 2014
Total Posts: 17143
29 Jan 2017 09:29 AM
It's no different from the way you do in the OP, just organized as an array.


Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:50 AM
I got a new Q now. How do you find the number of keys in an array? I tried #OurSystem and it prints 0.
Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 09:57 AM
Should i do some for loop to check for keys until key[i] = nil?
Report Abuse
Unsubtleties is not online. Unsubtleties
Joined: 28 Nov 2016
Total Posts: 9203
29 Jan 2017 10:06 AM
you mean the number of keys in a dictionary?

local length = 0

for _, _ in next, dictionary do
length = length + 1
end


Report Abuse
kaddad14 is not online. kaddad14
Joined: 13 Apr 2013
Total Posts: 649
29 Jan 2017 10:07 AM
Ty, that helps alot. Thx everyone.
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