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: Accessing a Table inside a Table.

Previous Thread :: Next Thread 
TilloFernandez is not online. TilloFernandez
Joined: 21 Mar 2015
Total Posts: 273
09 Sep 2016 04:46 PM
Dumb question, maybe.

local teams = {

Tourists = {nil,'Tourists','New Yeller'};
Developers = {1174589, 'Developers','Lime Green'};
}

- I'm trying to access the values inside the tables within the table. For example, I want to say Tourists[3] and have it print 'New Yeller' Code Example:

for i,v in pairs(teams) do

for i,x in pairs(v) do

print(x[3]);

end

end

prints: New Yeller, Lime Green

Ideas?
Report Abuse
Afro_Sub is not online. Afro_Sub
Joined: 16 Jun 2013
Total Posts: 1114
09 Sep 2016 04:47 PM
metatables

wiki.roblox.com


Report Abuse
Skelris is not online. Skelris
Joined: 02 Jan 2009
Total Posts: 4785
09 Sep 2016 04:47 PM
print(teams.Tourists[3])
Report Abuse
TilloFernandez is not online. TilloFernandez
Joined: 21 Mar 2015
Total Posts: 273
09 Sep 2016 04:47 PM
16:47:27.078 - Players.Player1.PlayerGui.TEAMS:12: attempt to index field '?' (a number value)
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Sep 2016 04:50 PM
local teams = {
Tourists = {nil,'Tourists','New Yeller'};
Developers = {1174589, 'Developers','Lime Green'};
}

print(teams.Tourists[2])

why not use dictionaries?

local teams = {
Tourists = {
ID = nil;
Name = "Tourists";
Color = BrickColor.new("New Yeller");
};
Developers = {
ID = 1174589;
Name = "Developers";
Color = BrickColor.new("Lime Green");
};
}
print(teams.Tourists.Name)
print(teams.Developers.Color.Name)

Report Abuse
Nuclear_Energy is not online. Nuclear_Energy
Joined: 21 Jul 2013
Total Posts: 1380
09 Sep 2016 04:51 PM
local teams = {

Tourists = {nil,'Tourists','New Yeller'};
Developers = {1174589, 'Developers','Lime Green'};
}

- I'm trying to access the values inside the tables within the table. For example, I want to say Tourists[3] and have it print 'New Yeller' Code Example:

for i,v in pairs(teams) do

for i,x in pairs(v) do

print(x[3]);

end

end

prints: New Yeller, Lime Green

Ideas? local teams = {

Tourists = {nil,'Tourists','New Yeller'};
Developers = {1174589, 'Developers','Lime Green'};
}

- I'm trying to access the values inside the tables within the table. For example, I want to say Tourists[3] and have it print 'New Yeller' Code Example:

for i,v in pairs(teams) do

for i,x in pairs(v) do

print(x[3]);

end

end

prints: New Yeller, Lime Green

Ideas? local teams = {

Tourists = {nil,'Tourists','New Yeller'};
Developers = {1174589, 'Developers','Lime Green'};
}

- I'm trying to access the values inside the tables within the table. For example, I want to say Tourists[3] and have it print 'New Yeller' Code Example:

for i,v in pairs(teams) do

for i,x in pairs(v) do

print(x[3]);

end

end

prints: New Yeller, Lime Green

Ideas?
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Sep 2016 04:52 PM
use a Dictionary like I stated

much cleaner and acts like they have parent-child relationship like roblox objects
Report Abuse
TilloFernandez is not online. TilloFernandez
Joined: 21 Mar 2015
Total Posts: 273
09 Sep 2016 04:53 PM
I rather do it, so I don't have to constantly add it manually.
Report Abuse
thedailyblarg is not online. thedailyblarg
Joined: 26 Feb 2012
Total Posts: 5506
09 Sep 2016 04:57 PM
yea and it sorts everything nicely so if you have like 10 indexes in your table, you might accidentally cause errors by missing or skipping a spot
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