Hi, getting some really weird behaviour which may be a Lua thing...?
I'm finding the index of a int value in a table using:
if indexOf(self.levelAvailable, self.cursorCoord) then
-- do something
self.levelAvailable[index] = nil
end
However, sometimes it just doesnt find it...I'm making a grid based sokoban type game and there are 4 or so available tiles and most of the time it fails to find them after a few have been set.
I don't know a whole lot about the implementation details of Lua. But the documentation for tables seems to indicate that lua doesn't care if a table is a sequence or not. Lua Manual 5.4 Values & Types
It points to the length operator which is only available on a table if it's a sequence, offers a more in-depth answer about how lua works if you're treating a table like an array. (Which it looks like you might be?) https://www.lua.org/manual/5.4/manual.html#3.4.7
Is cursorCoord an integer or a table? If it's a table (e.g. vector) you're comparing table ids instead of their values. It's also completely possible that table.indexOfElement stops when it hits nil. I guess that case would qualify as an SDK bug.
Generally speaking there are no arrays in the Lua language and an array-like table simply contains integer keys 1..N. Under the hood Lua does all sorts of optimization tricks and even uses actual C arrays, but you don't really need to care about those. In Lua you're always working with tables that are like objects or dictionaries in other languages.
Yes self.cursorCoord is an int. I was expecting the index of value to still work well enough if there was a table (array) of values, where most have been set to nil bar one or two, this is not teh case it seems... which is fine. table.remove works, just odd.