In this case you can just use
names[i]
.
The background is as follows: an array is a lua table with integer keys, starting from 1. So a three element array looks like this:
- Code: Select all
t[1] = "a"
t[2] = "b"
t[3] = "c"
Now if you leave a gap like this, a lot of code will stop working:
- Code: Select all
[code]
t[1] = "a"
t[2] = "b"
-- key 3 is not defined.
t[4] = "d"
Things like
#t
and
ipairs(t)
may assume there are only 2 elements in the array. Using
t[#t + 1]
makes sure you always insert with the next available key.
--
Roeland