Veloric
|
  |
| Joined: 24 Jul 2013 |
| Total Posts: 12668 |
|
|
| 08 Aug 2016 08:36 PM |
what does the i do in a for i,v in pairs() loop
like i never knew this
/Vel/ |
|
|
| Report Abuse |
|
|
Wowgnomes
|
  |
| Joined: 27 Sep 2009 |
| Total Posts: 26255 |
|
|
| 08 Aug 2016 08:37 PM |
identifier
part[i].transparency = 0 etc |
|
|
| Report Abuse |
|
|
|
| 08 Aug 2016 08:40 PM |
It iterates over a table/dictionary/list/array. (Different names, same thing in Lua)
i is the Index or Key, the position in the table where it is located. For a list/array, it is an integer ranging from 1 to more than you can count to in three hours. For a dictionary, it is the key which can be a string, number, Instance, pretty much anything.
v is the Value, the element in the table.
|
|
|
| Report Abuse |
|
|
Kodran
|
  |
| Joined: 15 Aug 2013 |
| Total Posts: 5330 |
|
|
| 08 Aug 2016 09:06 PM |
I think it helps to see an example.
local tab = {"a", "b", "c", "d"}
for i,v in pairs(tab) do print('index is '..i..', value is '..v) end
>index is 1, value is a >index is 2, value is b >index is 3, value is c >index is 4, value is d
Basically it runs the code in the loop for each value in the table, and for that value i is set to the index and v is set to the value. |
|
|
| Report Abuse |
|
|