I have the following table:
self.keytable = {}
self.keytable.rotate_right = false
self.keytable.rotate_left = false
self.keytable.thrust = false
self.keytable.brake = false
self.keytable.fire = false
I want to iterate through the table and set each value to false, but I must be missing some nuance of Lua. I’ve tried the following without luck:
for k,v in ipairs(self.keytable) do
v = false
end
Thanks in advance for any help!
i’m not exactly sure what your intent is here, but when working with non-integer keys you must use the pairs() built-in function. ipairs() is only to iterate tables with numeric keys, and in the example above you’re assigning false to non-numeric keys in keytable.
if you want to avoid having to set each key in keytable to false like you did in your code example, something like this would do what you want a little cleaner:
this produces this output when printed:
the code above just iterates over string values, and then sets them as the keys to keytable while assigning them the value false.