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
 

Easiest way to iterate through a nested dictionary?

Previous Thread :: Next Thread 
DigitalVeer is not online. DigitalVeer
Joined: 23 Jun 2009
Total Posts: 4182
03 Feb 2015 06:31 PM
If I have a dictionary:

container = {
["Question"] ={
["Question"] = "How are you?",
["Yes"] = "Good indeed, sir",
["No"] = "Quite bad, sir",
},
["Question"] ={
["Question"] = "How is your mother?",
["Yes"] = "Quite good, sir",
["No"] = "Very fat, sir",
},
["Question"] ={
["Question"] = "Is this working?",
["Yes"] = "Yes indeed, sir",
["No"] = "Unwantingly no, sir",
}

}

How can I obtain only the 'Question' arrays. Not the double nested ones but the singular ones using indexes?

For example,
How can I access the first Array using indexes such as:

counter = 1;
repeat
print(container[counter].Question);
counter = counter + 1;
until counter == 3
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
03 Feb 2015 06:36 PM
You can't, you're just replacing it when you define it multiple timesl ike that.
You'd have to do something like:

container = {
{Question = whatever, yes = blah, no = blah};
{Question = whatever, yes = blah, no = blah};
};

Then use your bottom method to do it.
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
03 Feb 2015 06:39 PM
Create your own iterator using a function that mimics next, or make a better organized table. You could put your question tables in their own table.

You can also check the index of a table with the pairs operator.

for index, var in pairs(tab) do
if index == "Question" then
-- do stuff
end
end
Report Abuse
LucasLua is not online. LucasLua
Joined: 18 Jun 2008
Total Posts: 7386
03 Feb 2015 06:40 PM
Also cnt makes a good point that you actually are overwriting it which I didn't realise in my post so do what he said.
Report Abuse
DigitalVeer is not online. DigitalVeer
Joined: 23 Jun 2009
Total Posts: 4182
03 Feb 2015 06:41 PM
Ah, Alright.
Thanks that solved the issue.
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