I wonder what ** [i]** mean. Can anyone explain how this works?
In a for
loop, you often have a variable called i
.
Example:
local table={"Hi", "there", "everyone!"} for i=1,#table do print(table[i]) end
In the for
loop, you have a variable called i
. It is a counter that is incremented every time the for
loop runs until i
is greater than #table
, which is the number of variables in table
.
You use [i]
to reference the i
th member in table
.
To add to chararray256's answer:
[i] on it's own doesn't mean anything, but square brackets are syntactical for indexing tables, i.e. accessing elements of the table that are stored with certain keys.
Take for example this code:
myTable = {"Hello", 7, Instance.new("Part")} print(myTable[1]) print(myTable[2]) print(myTable[3])
The output would read:
Hello 7 Part
Keys don't have to be numbers though, they can be strings as well!