Reputation: 33
I'm trying to iterate over many variables at once, which are stored in a long array. To initialise them, I'm using a loop which goes over each of them, setting every variable to 0. By default, e.g. using: array[count] = 0
it will only change the value of the table's index. How do I set this variable from inside the table, as in getting the variable stored inside and changing it, not just the table's value at the given index?
Upvotes: 0
Views: 2257
Reputation: 72412
You probably want to store fields in a Lua table:
a = { current = 4, first = 2, last = 10 }
Then you can set
a.current = 6
and also traverse all fields:
for k,v in pairs(a) do
print(k,v)
end
or clear them with
for k in pairs(a) do
a[k]=0
end
Upvotes: 2