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: Checking all Players for a IntValue

Previous Thread :: Next Thread 
NeonBlox is not online. NeonBlox
Joined: 19 Oct 2008
Total Posts: 1462
14 Nov 2011 05:17 PM
So each player has a IntValue called Tracker in them.

How do I search through all players to see which player's Tracker IntValue is equal to a?

Random Attempt:
a = 1
local plr = Game.Players:GetPlayers()
for i = 1, #plr do
if plr[i].Character.Tracker == a then
--stuff
else
end
end

I'm not the best.. :/
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
14 Nov 2011 05:19 PM
    a = 1
    for i, v in pairs(game.Players:GetPlayers()) do
        if v.Tracker.Value == a then
            --Do something
        else
            --Do something else
        end
    end
Report Abuse
NeonBlox is not online. NeonBlox
Joined: 19 Oct 2008
Total Posts: 1462
14 Nov 2011 05:31 PM
Would this work? The plr table was made earlier in the script, just so if people enter they don't get added into the mix when it checks again, I'd like to use the one made earlier.

local plr = Game.Players:GetPlayers()
--Tons of stuff
a = 1
for i, v in pairs(#plr()) do
if v.Tracker.Value == a then
--Do something
else
--Do something else
end
end
Report Abuse
kingkiller1000 is not online. kingkiller1000
Joined: 12 Dec 2008
Total Posts: 26415
14 Nov 2011 05:33 PM
for i, v in pairs(plr) do
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
14 Nov 2011 05:34 PM
That would not work, I'll leave a comment on the line(s) where you went wrong.

    local plr = game.Players:GetPlayers()
    --Tons of stuff
    local a = 1
    for i, v in pairs(plr) do --You're getting confused with a numeric for loop, this is a generic for loop.
        if v.Tracker.Value == a then
            --Do something
        else
            --Do something else
        end
    end

For more information on the generic for loop, go here:

http://wiki.roblox.com/index.php/Generic_for#pairs_and_ipairs
Report Abuse
NeonBlox is not online. NeonBlox
Joined: 19 Oct 2008
Total Posts: 1462
14 Nov 2011 05:36 PM
Ah, alright! Thanks.
Report Abuse
FoolHater is not online. FoolHater
Joined: 17 Jul 2008
Total Posts: 2141
14 Nov 2011 06:23 PM
I understand that ipairs() and pairs() are iterator functions that return table indices and their corresponding values.

I just want to understand the syntax of the for loop in this case.

"for i, v in pairs(plr) do"

--now does "i" stand for the table index and "v" stands for the value that index holds?

--I understand pairs() is a function whose argument is plr, a table, but does pairs() return a value?

--I am used to seeing "for i=1, 10 do" So is i and v stand in for "i=1" and "pairs(plr) stands in for "10". If so what does "in" mean?
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
14 Nov 2011 07:09 PM
1. Yes
2. No.
3. I and v represent key and value, nothing else.
Report Abuse
FoolHater is not online. FoolHater
Joined: 17 Jul 2008
Total Posts: 2141
14 Nov 2011 07:17 PM
so pairs() just iterates every key and value

Then what does the word "in" do? Is only for tables, specifying the key and value "in" ...
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
14 Nov 2011 07:18 PM
I honestly have no idea what in is there for. I just know it's in for loops, both generic and numeric.
Report Abuse
FoolHater is not online. FoolHater
Joined: 17 Jul 2008
Total Posts: 2141
14 Nov 2011 07:20 PM
I have never seen the word "in" in, for example, a numeric "for i=1, 3 do" loop. Are you referring to ipairs?
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
14 Nov 2011 07:21 PM
Oh, sorry. I was confuzzled.
Report Abuse
crazypotato4 is not online. crazypotato4
Joined: 22 Feb 2010
Total Posts: 20000
14 Nov 2011 07:27 PM
"2. No.
3. I and v represent key and value, nothing else."

wrong.

the pairs() function returns three values - next, the table it was called with, and nil. how generic for loops work is like this:

for [variable list] in [function list] do

for each iteration of the for loop, the first of [function list] gets called with the arguments being the rest of that list (since pairs() returns next, table, nil, this for loop calls the next function with arguments of the table and nil), and then the values that are returned by that function get passed to [variable list]. next returns the next key and value of the table, so i and v become those keys and values. once the [function list] returns nil, the for loop ends.

SO BASICALLY:

for -- da loop maker
i,v -- da variables
in -- another part of da loop maker
pairs(plr) -- this calls function pairs, returning next, plr, nil, so it calls next(plr,nil) every time the loop repeats, and the loop ends once next(plr,nil) returns nil
do -- moar partz of da loop maker

for i,v in pairs(plr) do
--?
end

though the original script that was posted would probably work just fine :l
Report Abuse
Pyzothon is not online. Pyzothon
Joined: 26 Oct 2011
Total Posts: 822
14 Nov 2011 07:34 PM
@crazypotato4

He forgot to put Tracker.Value.
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