Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Meaning the "i" in for i, object in pairs() ?

Asked by 7 years ago

What does mean i in:

for i, object in pairs()
end

3 answers

Log in to vote
2
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
7 years ago

Testing your code can reveal more than you'd think.

local t = {"a", "b", "c"}

for i, v in pairs(t) do
    print(i)
end
--Output: 1 2 3

i is the current index of the table, while v is the value. print is life!

If you don't know what an index and a value is, read this.

Ad
Log in to vote
1
Answered by
rexbit 707 Moderation Voter
7 years ago
Edited 7 years ago

i is the variable for index, basically representing the index, example.

local table = {number = 1, 5}

for index, value in pairs(table) do
    print(index,value)
end

this returns in the output

number 1

2 5

in this example number is the index and 1 is the value.

Log in to vote
0
Answered by 7 years ago

http://wiki.roblox.com/index.php?title=Global_namespace/Basic_functions&redirect=no#pairs

Answer this question