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: Why does table.foreach work but "for" loop not work?

Previous Thread :: Next Thread 
Dr_Doge is not online. Dr_Doge
Joined: 07 Dec 2011
Total Posts: 645
17 May 2016 06:49 PM
-- Code:

local hs = game:GetService("HttpService")
local Dictionary=hs:JSONDecode(hs:GetAsync("https://raw.githubusercontent.com/adambom/dictionary/master/dictionary.json", true))

local c = Dictionary
for i = 1, #c do
print(c[i])
end
warn'for loop done'

table.foreach(Dictionary,print)
warn'table.foreach done'

-- Note that the "Dictionary" table's JSON file is HUGE. Like Huger than Donald Trump.
-- Is that why it doest work?
-- Because the script is related to Donald Drumph?


Report Abuse
12103net is not online. 12103net
Joined: 08 Jul 2013
Total Posts: 350
17 May 2016 06:56 PM
or use pairs
Report Abuse
ArrowAvro is not online. ArrowAvro
Joined: 11 May 2016
Total Posts: 20
17 May 2016 06:56 PM
sample input looks like?

Report Abuse
fish_hook is not online. fish_hook
Joined: 24 Feb 2016
Total Posts: 6
17 May 2016 07:00 PM
If I'm correct, you can't refer to something in a dictionary with an integer by doing "dictionary[1]".
Report Abuse
Dr_Doge is not online. Dr_Doge
Joined: 07 Dec 2011
Total Posts: 645
17 May 2016 07:02 PM
output:

---------------------------------------------------------------------------------
> local hs = game:GetService("HttpService")
local Dictonary=hs:JSONDecode(hs:GetAsync("https://raw.githubusercontent.com/adambom/dictionary/master/dictionary.json", true))
local c = Dictonary
for i = 1, #c do
print(c[i])
end
warn'done'

16:43:07.956 - done


---------------------------------------------------------------------------------

> local hs = game:GetService("HttpService")
local Dictonary=hs:JSONDecode(hs:GetAsync("https://raw.githubusercontent.com/adambom/dictionary/master/dictionary.json", true))
table.foreach(Dictonary,print)
warn'done'


16:43:07.956 - LITHOPHYTIC Of or pertaining to lithophytes.
ELAN Ardor inspired by passion or enthusiasm.
MISCUE A false stroke with a billiard cue, the cue slipping from theball struck without impelling it as desired.
CONDYLOID Shaped like or pertaining to a condyle.
ATTEMPERATE Tempered; proportioned; properly adapted.Hope must be . . . attemperate to the promise. Hammond.
ADVANTAGE To give an advantage to; to further; to promote; to benefit; toprofit.The
ETC (TOO LONG TO PUT EVERYTHING)
16:43:07.956 - done
---------------------------------------------------------------------------------


Report Abuse
fish_hook is not online. fish_hook
Joined: 24 Feb 2016
Total Posts: 6
17 May 2016 07:06 PM
ex:
local not_a_dictionary = {1,2,3,4}
local dictionary = {me = 1, you = 2, us = 3, them = 4}
table.foreachi(dictionary, print) -- this won't print
table.foreachi(not_a_dictionary, print) -- this will print

so for it to work it would have to be
Report Abuse
Dr_Doge is not online. Dr_Doge
Joined: 07 Dec 2011
Total Posts: 645
17 May 2016 07:11 PM
@fish
wait wut...
table.foreach is the one that DOES work. The for loop dose not however.
Looking back, I realise I could have just put Dictionary for c...


Report Abuse
12103net is not online. 12103net
Joined: 08 Jul 2013
Total Posts: 350
17 May 2016 07:18 PM
for i,v in pairs(dictionary) do

end


or


print(unpack(dictionary))
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