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

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

Asked by
woodengop 1134 Moderation Voter
9 years ago

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

Log in to vote
3
Answered by 9 years ago

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.

0
So it can be Named anything, As long as it is in order? woodengop 1134 — 9y
0
Yes, it can, they can be anything. Vlatkovski 320 — 9y
0
What if I wanted to just use the Value instead of the Index? Would I have to add a "_, Index"? woodengop 1134 — 9y
0
Thanks anyways! woodengop 1134 — 9y
0
Using "i,v" is the same as "_,v". You can leave the index if you don't need it. Vlatkovski 320 — 9y
Ad
Log in to vote
1
Answered by 9 years ago

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

0
Thanks! +1 Bro. woodengop 1134 — 9y
0
No problem, thanks for the point. aquathorn321 858 — 9y

Answer this question