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: Can someone explain to me was "in pairs" does

Previous Thread :: Next Thread 
ScarletArmada is not online. ScarletArmada
Joined: 06 Jul 2014
Total Posts: 11541
11 Jul 2016 02:59 PM
The wiki didn't help me that much.


Frugal Kitchens & Cabinets™; "Life happens here!" https://www.youtube.com/watch?v=WM9Qi15g6V0
Report Abuse
JarodOfOrbiter is not online. JarodOfOrbiter
Joined: 17 Feb 2011
Total Posts: 20029
11 Jul 2016 03:00 PM
Pairs is a stateless iterator, and it is used to iterate over dictionaries. That's about it.

for Key, Value in pairs(Dictionary) do


Report Abuse
FireController1847 is not online. FireController1847
Joined: 17 Jan 2013
Total Posts: 1828
11 Jul 2016 03:01 PM
It's pretty much the same as this,

for i,v in pairs do
-- script
end

I is the place value of the object
V is the object in the thing, so...

(THIS SCRIPT WONT WORK, JUST AN EXAMPLE FOR CONCEPT)

local array = {"object1", "object2", game.Workspace.Name}

for i,v in pairs array do
print(i)
print(v)
end

Output:
1
object1
2
object2
3
workspace


#code function brag() print("R$686") end
Report Abuse
ScarletArmada is not online. ScarletArmada
Joined: 06 Jul 2014
Total Posts: 11541
11 Jul 2016 03:01 PM
Ah ok. Thanks


Frugal Kitchens & Cabinets™; "Life happens here!" https://www.youtube.com/watch?v=WM9Qi15g6V0
Report Abuse
Egzekiel is online. Egzekiel
Joined: 10 Jan 2011
Total Posts: 1079
11 Jul 2016 03:02 PM
for index,value in pairs(workspace:GetChildren()) do
--stuff
end

pairs takes an index, which, in the table, is the number of the value (like, if the workspace is iterated through and "Baseplate" is the first then index=1) and a value, which is the actual instance/value of the table (if "Baseplate" is first then v.Name=="Baseplate")

It iterates through the table given in parenthesis.

Try to run this code in the command bar:

for i,v in pairs(workspace:GetChildren()) do
print(i,v)
end


Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
11 Jul 2016 04:01 PM
Non-technical explanation:
for key, value in pairs(tbl) do
will iterate over all key-value pairs in the table 'tbl'

Technical explanation:
docs.google dot com/document/d/1KlrlNYNfVKyvTbmJBoVODOqMJF-wTn_JbGUEm0G6RIM
scroll down to "Generic For Loop"
Report Abuse
TimeTicks is not online. TimeTicks
Joined: 27 Apr 2011
Total Posts: 27115
11 Jul 2016 04:19 PM
for i,v in next, tab do
print(i,v)
end


Report Abuse
RangerDelta is not online. RangerDelta
Joined: 10 Jul 2016
Total Posts: 1194
11 Jul 2016 04:21 PM
@Cntkillme

I'm looking to learn more about the technical side of Lua because of your posts here, you're able to articulate in ways many people here can't because they don't know the terminology.

Do you have any other resources like that?


Report Abuse
Flux_Capacitor is not online. Flux_Capacitor
Joined: 07 Apr 2008
Total Posts: 45720
11 Jul 2016 04:31 PM
Here's another one:
docs.google dot com/document/d/1A1SBjRqFKFxaw7_RnsI96CKzBCcAOkuDPOTG8DIZywA
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