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: for loop

Previous Thread :: Next Thread 
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
20 Jan 2016 05:12 PM
for _,v in pairs(game.Players:GetChildren()) do
if not v.Backpack:FindFirstChild("HyperLaserGun") then
h = rps:WaitForChild("HyperLaserGun") -- whatever name it is
h:Clone()
h.Parent = v.Backpack
end
end

Can someone explain to me why v is referred to the player?
Report Abuse
ThoughtConduit is not online. ThoughtConduit
Joined: 30 Nov 2015
Total Posts: 536
20 Jan 2016 05:13 PM
because this type of loop is like looping through a table of players, where each value, v, is a player.


Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
20 Jan 2016 05:15 PM
for _,player in pairs(game.Players:GetPlayers()) do
if not player.Backpack:FindFirstChild("HyperLaserGun") then
local h = rps:WaitForChild("HyperLaserGun"):clone()
h.Parent = player.Backpack
end
end
Report Abuse
CloneTrooper1019 is not online. CloneTrooper1019
Joined: 19 Jan 2009
Total Posts: 6227
20 Jan 2016 05:19 PM
Oh right, the explanation.
Basically, the pairs function constructs an iterator function, which when called, returns the next key/value pair in the table, or nil if it reached the end of the table.

The for loop continues to call the iterator, and runs a loop with those variables until it iterates through each key/value in the table.
Report Abuse
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
20 Jan 2016 07:41 PM
OMY GOD OH MY GOD ITS CLONETROOPER HE RESPONDED TO MY POST HEY CLONE WASUUUUPPPPPPP!!!!!!!!!
Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
20 Jan 2016 07:50 PM
The ROBLOX Wiki Staff consists of strong material. They help people. They will not respond to your non-sense, swim.
Report Abuse
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
20 Jan 2016 07:52 PM
so clone v is like the "value" so what your saying is v can be anything? For example, I could technically do for _, bananas in pairs(game.Players:GetPlayers())?
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
20 Jan 2016 07:53 PM
"OMY GOD OH MY GOD ITS CLONETROOPER HE RESPONDED TO MY POST HEY CLONE WASUUUUPPPPPPP!!!!!!!!!"

I cringed
Report Abuse
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
20 Jan 2016 07:56 PM
guys leave.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
20 Jan 2016 07:57 PM
Yes, you cuold
Report Abuse
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
20 Jan 2016 07:58 PM
thank you guys!
Report Abuse
62GB is not online. 62GB
Joined: 03 Oct 2011
Total Posts: 4157
20 Jan 2016 07:59 PM
'v' is just the variable that holds the value in the iteration. It can be anything.
Report Abuse
ForeverDev is not online. ForeverDev
Joined: 04 Oct 2008
Total Posts: 13300
20 Jan 2016 08:01 PM
v is just a variable name. '_' is also just a variable name. It's usually 'i' for 'index'.

local tab = {1, 1, 2, 3, 5, 8, 13, 42}

for index, value in ipairs(tab) do
print(index, value)
end

outputs

1 1
2 1
3 2
4 3
5 5
6 8
7 13
8 42

as you can see, the first thing that is printed is the current index. the second thing that is printed is value. value is equal to tab[index]
Report Abuse
swimmaster07 is not online. swimmaster07
Joined: 08 Jun 2013
Total Posts: 1459
20 Jan 2016 08:10 PM
ok thx!
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