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
 

Re: Two questions about generic loops.

Previous Thread :: Next Thread 
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:10 PM
1) What does i,v mean when you say generic loops?

2) What's the difference between pairs and ipairs?
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:15 PM
Anyone?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
03 Sep 2011 02:15 PM
They're the things returned by the iterator (which is the 'next' function). ipairs ignores non-numeric indices, pairs doesn't.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:17 PM
-_-

I'm gonna learn generic loops soon, so that doesnt make sense to me one bit.Is there some kind of example or can you explain it a different way?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
03 Sep 2011 02:19 PM
In short, when using pairs or ipairs, i is the index, v is the value.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:20 PM
Can you give me a simple example?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
03 Sep 2011 02:26 PM
MyTable = {"I", "like", "WiseBot"}
for i, v in pairs(MyTable) do
print(i,v)
end

1 I
2 like
3 WiseBot
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:32 PM
Ok, what in that print waht does i and v mean?And if you used ipairs would it still work?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
03 Sep 2011 02:32 PM
I told you, i is the index, v is the value. And yes, it would work with ipairs.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:37 PM
Ok, whats better to say?ipairs or pairs or does it not matter?

Also, so your saying that like v is Mytable and i is I, Like, robot?
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
03 Sep 2011 02:38 PM
Use pairs, unless you want to only iterate through numeric indexes.
Report Abuse
miz656 is not online. miz656
Joined: 19 Jul 2010
Total Posts: 15336
03 Sep 2011 02:39 PM
Ok andwas I right about the v and i?
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