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 » Scripting Helpers
Home Search
 

Ipairs, pairs, and the "for i = 1, #Array do"

Previous Thread :: Next Thread 
logitech101 is not online. logitech101
Joined: 02 Mar 2008
Total Posts: 93
29 Sep 2012 10:15 PM
Whats the real dfference between them?

I always used the for i = do with tables and stuff... Like :GetChildren()

But I never knew what pairs and ipairs are and why they're better...

I just figured theyre better cause all the pro scripters use them over for i = do :\
Report Abuse
AIAdvance is not online. AIAdvance
Joined: 28 Sep 2012
Total Posts: 18
29 Sep 2012 10:21 PM
Differences

Table = {"Win",nil,"Black"}

for n=1,#Table,1 do
print(Table[n])
end
> Win
nil
Black

for n,o in pairs(Table)do
print(n,o) -- n is the same n as the first for loop, o is the value
end
> 1 Win
2 nil
3 Black

for n,o in ipairs(Table)do
print(n,o)
end
> 1 Win

Why didn't the last one print 2 nil 3 Black? Because ipairs stops when it reaches the first nil value, where as pairs runs through the whole table.
Report Abuse
logitech101 is not online. logitech101
Joined: 02 Mar 2008
Total Posts: 93
29 Sep 2012 11:29 PM
k thx :P Good luck on your AI :D
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • 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