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
We use cookies to offer you a better experience. By using Roblox.com, you are agreeing to our Privacy and Cookie Policy.
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: in pairs?

Previous Thread :: Next Thread 
dude6354 is not online. dude6354
Joined: 04 Apr 2009
Total Posts: 205
29 Apr 2013 09:33 PM
Can someone explain to me what "in pairs" means in lua? I was given this code on a post that i made in scripting helpers, and i understand everything but "in pairs". if someone could shed some light on this situation i would really appreciate it.

Also, here is that code i was talking about.

function HowManyAlive()

local Alive = { };
for _, Player in pairs(Game.Players:GetPlayers()) do
if Player.Character:FindFirstChild("Humanoid").Health > 0 then
table.insert(Alive, Player);
end;
end;
return Alive;
end;

if #HowManyAlive() == 1 then
print(HowManyAlive()[1]);
elseif #HowManyAlive() <= 0 then
print("No one is alive");
end;
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
29 Apr 2013 09:37 PM
for _, Player in pairs(Game.Players:GetPlayers()) do

_ = index
Player = value

pairs(x)
Where x is, you put a table

Basically, it loops through all the values in a table that you give it.
Note that you can change _ and Player to w/e variable name you want it to be.
Report Abuse
dude6354 is not online. dude6354
Joined: 04 Apr 2009
Total Posts: 205
29 Apr 2013 09:40 PM
Oooooh! Thank you so much! That makes sanse lol. Also, mind if i ask one more quick question? to check and see if a name is in a table with an if statement, wouldnt it be:

if Player in Table then

or something like that
Report Abuse
ScrewDeath is not online. ScrewDeath
Joined: 03 Jun 2012
Total Posts: 2700
29 Apr 2013 09:51 PM
The basic syntax is:
for index,value in pairs(table)

So no, it wouldn't work.

You would have to be like...

for i,v in pairs(table) do
if v.Name == Player.Name then
return true
end
end


Report Abuse
dude6354 is not online. dude6354
Joined: 04 Apr 2009
Total Posts: 205
29 Apr 2013 09:58 PM
Oh okay, thanks :)
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