Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

What is "i" and "v" in the "In Pairs"?

Whenever I use the In Pairs, I couldn't Understand the index, and the value, Like for example, I have a Box with a Car in it, would the Box(outside) be the index, and the value would be the Car INSIDE the Box?

Please Respect that I am a Scripter in need for Knowledge

2 answers

✓ Accepted answer

It's kind of hard to explain, but:

Table = {
	Index = Value
}

Index and value could be anything.

If an index isn't assigned but a value is, the index will be the length of the table + 1. For example:

Table = {}
table.insert(Table, "hello")

"hello" will have an index of 1 because the table is empty.

5 comments

0

So it can be Named anything, As long as it is in order?

0

Yes, it can, they can be anything.

0

What if I wanted to just use the Value instead of the Index? Would I have to add a "_, Index"?

0

Thanks anyways!

0

Using "i,v" is the same as "_,v". You can leave the index if you don't need it.

Index is the Interval, and Value is the value of the table. i and v are just variables for index and value. You can change them to whatever you'd like. Here's how pairs would look in a while loop:

local tab = {"one","two","three","four","five"}

local i = 0

while i < #tab do
i = i + 1
v = tab[i]
end

Here's an example of how the variables can be changed:

local admins = {"Player","Player1","aquathorn321","TheContinentofEurope"}
local admin == "aquathorn321"

for number, player in pairs(admins) do
if player == admin then
print(admin.." Is an admin!")
end
end

2 comments

0

Thanks! +1 Bro.

0

No problem, thanks for the point.

This discussion is preserved as it was. New answers, comments, and votes are closed.