Closed FirstVertex closed 2 years ago
reopening, as i am still seeing this behavior after further debugging and isolation. please do investigate this, and i apologize for prematurely closing it.
Remote definition and usage
const Remotes = Net.Definitions.Create({
AllP: Definitions.ServerToClientEvent<[allPlayers: IPlayerInit[]]>()
});
Server fire
AllPEvent.SendToPlayer(player, allPlayersInit);
Client receive
AllPEvent.Connect((allPlayers: IPlayerInit[]) => {
print('client: ALLP recd is', allPlayers)
});
How did you get an array with zero indexes? roblox-ts should be starting from 1
. The issue here is that JSON encoding your table produces string keys. I don't think Net has a way around this
hello, this is a message to transfer the state of an infinite Queue, as discussed on this page from Lua handbook
https://www.lua.org/pil/11.4.html
From this I use pushLeft()
to insert new points to the buffer, and popRight()
to expire old ones
Lua handbook assures me it is ok to use 0 and negative numbers for indexing table.
this represents a stream of points emitting from player's motion.
i was able to isolate this to arrays whose indices do not begin with 1. any way to fix that? i have a separate message involving this exact same sub structure who sends points that begin with index 1, and the key received is int. other messages with the same structure who use a negative or zero key to start, have their int keys stringified.
it is not sparse array. the indices sent are always sequential and grouped together, although potentially negative. ipairs to iterate it works.
closing as an issue with my code. i need to change the transmitted DTO to be normalized to an array with positive indices that start with 1 and can be iterated. then the received array always has the correct numeric keys.
Yeah this is an issue with how JSON is encoded. Unfortunately not something I can fix.
I sent a message from Server to client with array of point data. It's just a normal array with integer keys.
When client received the array, the keys are turned into string. It causes bad problems with iteration.
Here's what server sent:
Notice the path to the first player's first point is
[1].bs.pts[0]
- and the0
is an integer.Here's what client received:
the path to the first player's first point is now
[1].bs.pts["0"]
- and the"0"
has turned to a string.The topmost level was recognized as an array and interpreted correctly. The nested array was the one with the problem.
Here is corresponding type definition of
IPlayerInit
structure. Payload is array of this. Nested inside isbs: IBufferState
with array ofIBufferPoint
pts