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: Can someone remind me of how to use in pairs?

Previous Thread :: Next Thread 
form2275 is not online. form2275
Joined: 09 Jul 2007
Total Posts: 6041
24 Jul 2011 10:57 PM
I had an example, but I accidently deleted it. :/

I thing it was something like:

table={}
for _,v in pairs table do
end
Report Abuse
FirmFlyerCoced59 is not online. FirmFlyerCoced59
Joined: 13 Mar 2010
Total Posts: 448
24 Jul 2011 10:59 PM
uhh gosh i suck at lua i need help.
Report Abuse
form2275 is not online. form2275
Joined: 09 Jul 2007
Total Posts: 6041
24 Jul 2011 11:01 PM
I found my mistake. I forgot the (). sorry.

it should be:

table={}
for _,v in pairs(table) do
end
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
24 Jul 2011 11:03 PM
table = { "ABC , 123 }

for i,v in pairs(table) do

print(i .. " " .. v)

end

>1 ABC
>2 123

i (the first argument) is the index of the value in the table, and v (the second value) is the value of that index in the table.
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
24 Jul 2011 11:04 PM
Fixes, forgot to close the quote "ABC" and should've said v is the second argument, not value.
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
24 Jul 2011 11:04 PM
I suggest you use next, instead, since it is more efficient.

local tab = {"A", "B", "C"}

for i, letter in next, tab do
  print(letter)
end

It runs faster than pairs.
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
24 Jul 2011 11:06 PM
What is 'next?' i've never heard of that... an explanation or wiki page would be fantastic, I'm always interested in new concepts :D
Report Abuse
form2275 is not online. form2275
Joined: 09 Jul 2007
Total Posts: 6041
24 Jul 2011 11:39 PM
@JulienDethurens
Thanks, never heard of next before.

@BladzofChaos70
Thanks for in info on in pairs()
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
24 Jul 2011 11:44 PM
"What is 'next?' i've never heard of that... an explanation or wiki page would be fantastic, I'm always interested in new concepts :D"

Pairs and ipairs both use next. If you need info about it, go look on the Lua reference manual on lua.org.
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
25 Jul 2011 12:01 AM
I apologize for having never heard of that term before, next time I will try to know the thing I don't know about. Now that i've heard about it it makes sense & i figured pairs/ipairs did something of the sort.

(btw, I apologize for my for statement if you weren't intending to be rude, that's just how I first interpreted it)
Report Abuse
Spectrumw is not online. Spectrumw
Joined: 04 Aug 2009
Total Posts: 13510
25 Jul 2011 12:03 AM
"I will try to know the thing I don't know about."

Oh mai D: paradox much?
Report Abuse
JulienDethurens is not online. JulienDethurens
Joined: 11 Jun 2009
Total Posts: 11046
25 Jul 2011 12:05 AM
Just so you know, using a numeric for loop is way more efficient than using pairs/ipairs/next [PROVEN].
Report Abuse
BladzofChaos70 is not online. BladzofChaos70
Joined: 27 Sep 2008
Total Posts: 2550
25 Jul 2011 12:06 AM
That was the point, the way I first interpreted what he said it seemed like he was annoyed that I didn't know about 'next' and was annoyed that I was asking about it, so basically for his convenience next time I'll just somehow know about something instead of asking. (Aren't retorts/jokes always the best when they have to be explained? XD)
Report Abuse
form2275 is not online. form2275
Joined: 09 Jul 2007
Total Posts: 6041
25 Jul 2011 12:23 AM
I was going to use this for a part of my script to get all the players.

Thanks.

for _,player in next, game.Players:GetChildren() do
end

--@JulienDethurens, Is the bellow script what you meant by numeric for loop?

player=game.Players:GetChildren()
for i,1#player do
end
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