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: Is there any way to find tables in a table?

Previous Thread :: Next Thread 
Twistir is not online. Twistir
Joined: 19 Nov 2009
Total Posts: 12374
25 Jan 2015 12:48 AM
I desperately need to do something like this below. The problem with this is that i cant find the different items through shirtids[1]. I have been told already that it doesnt work because I cant have a table inside a table.

shirtids = {
s1 = {textureid=200029202,thumbid=200029204,cost=200},
s2 = {textureid=200029202,thumbid=200029204,cost=200},
s3 = {textureid=200029202,thumbid=200029204,cost=200},
s4 = {textureid=200029202,thumbid=200029204,cost=200},
s5 = {textureid=200029202,thumbid=200029204,cost=200},
}
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
25 Jan 2015 12:50 AM
shirtids.s1 returns the table 's1'.
These are just known as multidimensional tables.


::_::goto_
Report Abuse
Twistir is not online. Twistir
Joined: 19 Nov 2009
Total Posts: 12374
25 Jan 2015 12:53 AM
okay how could I do something like #shirtids
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
25 Jan 2015 12:59 AM
By that, I'm assuming you are asking how to implement a loop?
Well, a numeric loop can be implemented, but not in the way you'd think.

for i=1,#shirtids,1 do
local ind = i-1;
local k,v = next(shirtids, ind);

-- now, the table within shirtids is stored in the variable 'v'.
-- perform any actions your would've done to the table.
end;


::_::goto_
Report Abuse
Twistir is not online. Twistir
Joined: 19 Nov 2009
Total Posts: 12374
25 Jan 2015 01:06 AM
so s1-5 is now defined as v?
Report Abuse
blobbyblob is not online. blobbyblob
Joined: 29 Oct 2008
Total Posts: 12165
25 Jan 2015 01:10 AM
Is having them be named 's1', 's2', etc. even important? You can just treat them as numerical indices as follows:

shirtids = {
{textureid=200029202,thumbid=200029204,cost=200},
{textureid=200029202,thumbid=200029204,cost=200},
{textureid=200029202,thumbid=200029204,cost=200},
{textureid=200029202,thumbid=200029204,cost=200},
{textureid=200029202,thumbid=200029204,cost=200},
}

print(shirtids[1].cost); --> 200
Report Abuse
Twistir is not online. Twistir
Joined: 19 Nov 2009
Total Posts: 12374
25 Jan 2015 01:12 AM
thanks blob, I always make things a little bit more complicated to the point where they dont work lol
Report Abuse
KOTwarrior is not online. KOTwarrior
Joined: 13 Jun 2012
Total Posts: 4376
25 Jan 2015 01:13 AM
I'd forgotten that '#' doesn't work on dictionaries, but here's a simple workaround.

local k,v = next(shirtids,nil);
while k do
-- do stuff to v, v being the table s1-5.
k,v = next(shirtids,k);
end;
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