The encoding stops when a nil value is encountered in the Lua table, and it is unclear whether this is intended behavior.
could have done this better but it’s 4:20 am sorry >_>
The encoding stops when a nil value is encountered in the Lua table, and it is unclear whether this is intended behavior.
could have done this better but it’s 4:20 am sorry >_>
This is intended behaviour, when you have a table of non-sequential numeric indeces it is not considered an array but will be interpreted as a hashmap, however there are still ordered indeces (such as 1,2) so that will be interpreted as an array. In Luau, tables have an array part and a hash part. This usually works out fine when just handling the table normally, however when passing it over the network the game has to choose wether or not to send the hash or the array part. From testing, it tends to send the array part.
This issue mostly boils down to tables in Lua not making a hard distinction between dictionaries and arrays. When sending data, Roblox assumes that a table with number indices is an array that only contains non-nil values. It basically just loops over them the same way as ipairs does. This is intended behavior.
I’m not against this behaviour changing. But typically what I do to circumvent this is send 2 complete arrays. The first array has placeholder index to actual index, and the second array has the data in complete array form.
Example:
local tableToSend = {
[1] = true,
[2] = false,
[4] = "cuh",
[267] = "cuh2",
}
-- converts to
local indexArray = {
[1] = 4,
[2] = 1,
[3] = 267,
[4] = 2,
}
local dataArray = {
[1] = "cuh",
[2] = true,
[3] = "cuh2",
[4] = false,
}
Which gets around this issue without terribly unnecessary network usage.