Ohhhhhhh, I get what v does now
the i
thing is the index which is the number of the instance (1,2,3,4,5,etc)
so it prints the number of the value?
for example: you have 50 instances inside workspace, it will keep printing from 1 until its 50.
it just prints out its index, aka, its number in line
oh I think I get what the i, and v does now
but how about the ipairs()?
ipairs() works in the i,v format (index, value),
pairs() works in the k,v format (key, value).
ipairs()
ensures that the indices are iterated in numerical order (1, 2, 3, 4, 5,etc)
pairs()
returns all keys and values out of order (5,2,4,1,3,etc)
Iāll be away from my laptop for minutes
thats a better explanation than mine ngl.
pairs()
is not ākinda unpredictableā, pairs()
both traverses Array and Dictionary parts of a Table, meanwhile ipairs()
only traverses the Array part of a Table.
Due to the new syntax update which allows Luau to do the iteration without pairs()
internally, the usage of pairs()
is no longer necessary. However, if you still want to iterate through the Array part of a table, you need to use ipairs()
.
Thank you for correcting me. I genuinely did not know that.
Iām back and thanks for the explanation ANDRO
I understand how both work now thank you all for the help
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.