For @ConveyedRex7592, you can also assign numbers via:
local planetNames = {
[0] = "Arena",
[1] = "Purpz-4658",
[2] = "Goldy-5269",
[3] = "Desert-1256",
[4] = "Grassy-3654",
[5] = "Cyany-3421",
[6] = "Earthy-1234",
[7] = "Rocky-4325",
[8] = "Ball-2436",
[9] = "Pinky-5451",
[10] = "Greeny-7266",
}
Or just leave the index out and it’ll work like tntwickey pointed out.
Also, like SGS already said, zeros and negative numbers can be used as indices, but Lua always starts adding to tables from index 1.
ipairs
would ignore zeros and negative values, but there’s also an issue that both ipairs
and #
operator will only iterate until the first nil index in the table. In other words, if you were to comment out the line [1] = "Purpz-4658",
then using ipairs
or #
would state that the length of the table is 0.
But, since you are in control of your code and you know what it needs to do, you could use for loops that start from zero or negative indices and there’d be no issues.