Also, from what I understand this shouldn’t be too hard to fix, at the moment it uses json which doesn’t support mixed tables so would just need a different serialisation function for tables?
And if I did encode it in whatever beforehand, that would require each script that connects to the event decode it, which is not very performant nor very usable in terms of third party modding of any script I make ( This is for a free model that supports third-party mods )
Why do you have mixed tables? There are few cases where I find mixed tables to actually be the right design choice. Could you break up these tables into nested tables with sequential and referential parts? What is just one example where you are having trouble sending a mixed table?
Ultimately, the issue probably lies in the fact that you are mixed data structures. A mixed index table isn’t really a true data structure. You are combining an array with a map and that really doesn’t make sense from a computer science perspective.
This is incorrect, all sub-tables (and sub-sub-tables, and sub-sub-sub, etc…) need to be non-mixed right now. The property applies to the entire structure of tables, not just top-level. (This is most likely because it is marshalled into JSON internally)
> workspace.Event:Fire(
{
"hello",
{
[2] = "world",
[5] = "!!!"
}
}
)
18:02:44.507 - Cannot convert mixed or non-array tables: keys must be strings
As a temporary workaround, if your keys can only be numbers, you can just tostring the indices that you set and then turn them back into numbers at the receiving end.
That’s because in the first example, you have an array of numerical indices but it doesn’t start at 1 (and also it may have no holes, if there were multiple indices). In the second example, you don’t supply any indices, so it just becomes an array which is allowed.
If you actually print the result of that table being passed through a Bindable/RemoteEvent, you’d find that the B = 1 probably got cut off. That’s Roblox’s mistake for not throwing an error there.
Figured out I can use the following function to make it work for now:
local function Fill( Table, a, max )
a = a or 1
if not max then
max = 1
for a, b in pairs( Table ) do
max = math.max( max, a )
end
end
if a > max then return end
return Table[ a ], Fill( Table, a + 1, max )
end
This code demonstrates the culling that will occur.
local bindable = Instance.new("BindableEvent")
local function printTable(tab, depth)
depth = depth or 0
local indent = string.rep("\t", depth)
for i, v in pairs(tab) do
if type(v) == "table" then
print(indent .. i .. " : {")
printTable(v, depth + 1)
print(indent .. "}")
else
print(indent .. i .. ": " .. tostring(v))
end
end
end
bindable.Event:Connect(printTable)
bindable:Fire({ 1, 2, 3, B = 1 })