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: Whats the difference?

Previous Thread :: Next Thread 
LV1Z is not online. LV1Z
Joined: 23 Jul 2011
Total Posts: 652
26 Sep 2013 06:01 PM
between ipairs and pairs
Report Abuse
Salinas23 is not online. Salinas23
Joined: 28 Dec 2008
Total Posts: 37142
26 Sep 2013 06:02 PM
http://wiki.roblox.com/index.php/Ipairs#ipairs

I have a spider on my back.
Report Abuse
databrain is not online. databrain
Joined: 01 Jan 2013
Total Posts: 3342
26 Sep 2013 06:36 PM
Ipairs is for getting the number of what your indexing.
like this:
tab = {"A", "B", "C"}
for i,v in ipairs(tab) do
print(i, v)
end

will print:
1 A
2 B
3 B

Pairs is for getting key values (Which is not the most useful thing in the world, but works well when trying to store 2 values to the same meaning in a table)
like this:
tab = {}
tab['foo'] = "bar"
tab['Hello,'] = "world!"
for k,v in pairs(tab) do
print(k, v)
end

will print:
foo bar
Hello, world!

The l0z3r p00p3r of ATR
Report Abuse
LV1Z is not online. LV1Z
Joined: 23 Jul 2011
Total Posts: 652
26 Sep 2013 06:50 PM
ty
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Sep 2013 06:53 PM
Don't ever use ipairs (numeric for's work the same, but MUCH faster, and pairs works the samish, but faster)
Report Abuse
LV1Z is not online. LV1Z
Joined: 23 Jul 2011
Total Posts: 652
26 Sep 2013 08:10 PM
i always use ipairs
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Sep 2013 08:13 PM
Then you are adding invisible lag
Report Abuse
LV1Z is not online. LV1Z
Joined: 23 Jul 2011
Total Posts: 652
26 Sep 2013 08:14 PM
which i do not get cuz i have a gaming pc, in which I built
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 Sep 2013 08:15 PM
Doesn't matter, it still adds lag to the server if it's in a server-sided script.
Not really noticeable, but still.

If you want to illiterate over, let's say workspace, the fastest way of doing it is:
x = workspace:GetChildren()
for i=1, #workspace do
--code
end

Which is more than twice as fast as ipairs
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