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
10 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 10 years ago

It's kind of hard to explain, but:

1Table = {
2    Index = Value
3}

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:

1Table = {}
2table.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 — 10y
0
Yes, it can, they can be anything. Vlatkovski 320 — 10y
0
What if I wanted to just use the Value instead of the Index? Would I have to add a "_, Index"? woodengop 1134 — 10y
0
Thanks anyways! woodengop 1134 — 10y
0
Using "i,v" is the same as "_,v". You can leave the index if you don't need it. Vlatkovski 320 — 10y
Ad
Log in to vote
1
Answered by 10 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:

1local tab = {"one","two","three","four","five"}
2 
3local i = 0
4 
5while i < #tab do
6i = i + 1
7v = tab[i]
8end

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

1local admins = {"Player","Player1","aquathorn321","TheContinentofEurope"}
2local admin == "aquathorn321"
3 
4for number, player in pairs(admins) do
5if player == admin then
6print(admin.." Is an admin!")
7end
8end
0
Thanks! +1 Bro. woodengop 1134 — 10y
0
No problem, thanks for the point. aquathorn321 858 — 10y

Answer this question