AvailableSpots = {
["1"] = true;
["2"] = true;
["3"] = true;
}
for i,v in pairs(AvailableSpots) do
print(i)
print(v)
end
output
1
true
3
true
2
true
Why does it skip to 3? How would I fix this?
AvailableSpots = {
["1"] = true;
["2"] = true;
["3"] = true;
}
for i,v in pairs(AvailableSpots) do
print(i)
print(v)
end
output
1
true
3
true
2
true
Why does it skip to 3? How would I fix this?
The order a table is written in is not preserved unless your keys are numerical. In your case, this shouldn't be a problem, as your string keys can just as easily be numbers:
AvailableSpots = {
[1] = true;
[2] = true;
[3] = true;
}
for i, v in pairs(AvailableSpots) do
print(i, v)
end
This discussion is preserved as it was. New answers, comments, and votes are closed.
1 comment
This is probably because the pairs function doesn't have a specified key order, if you want a specified key order, convert your table into an array, then use ipairs https://stackoverflow.com/questions/55108794/what-is-the-difference-of-pairs-vs-ipairs-in-lua