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

what is "[i]" and "[[i]]" Used for?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

I have seen it only in Person299's admin commands but I have Absolutely No Idea how it is used Any help would be much appreciated!

1 answer

Log in to vote
1
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

In a table, you can take the table's name followed by brackets and a number, and that gives you the value corresponding to the number, like this:

MyTable = {"Hi","People","I'm","Perci1!"}
print(MyTable[1])
print(MyTable[3])

--output: Hi, I'm

If you have a variable for a number and that variable is changing, like in a for loop, then you can affect every value in a table in a very short amount of time.

MyTable = {"Hi","People","I'm","Perci1!"}

for i = 1,#MyTable do --#MyTable is the amount of values in the table. In this case, 4.
    print(MyTable[i]) --Since i changes each time, we will print all the values in the table one at a time.
end

--output: Hi, People, I'm, Perci1!
0
THANKS :D IcyEvil 260 — 10y
0
No problem c: Perci1 4988 — 10y
Ad

Answer this question