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
It's kind of hard to explain, but:
1 | Table = { |
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:
1 | Table = { } |
2 | table.insert(Table, "hello" ) |
"hello"
will have an index of 1 because the table is empty.
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:
1 | local tab = { "one" , "two" , "three" , "four" , "five" } |
2 |
3 | local i = 0 |
4 |
5 | while i < #tab do |
6 | i = i + 1 |
7 | v = tab [ i ] |
8 | end |
Here's an example of how the variables can be changed:
1 | local admins = { "Player" , "Player1" , "aquathorn321" , "TheContinentofEurope" } |
2 | local admin = = "aquathorn321" |
3 |
4 | for number, player in pairs (admins) do |
5 | if player = = admin then |
6 | print (admin.. " Is an admin!" ) |
7 | end |
8 | end |