Storing Dispatched Codes/Data

Hello @Rob161, I think that recreating the state of the game on the client by replaying all of the messages in sequence may be very inefficient, unless there’s not that many messages exchanged. If possible, I’d suggest you create a snapshot state of the game that allows the client to recreate it without having to go through all the messages.

If you really wish to do it that way, then I suggest you go through all the messages and send them one-by-one to the client through a websocket connection.

Also in your snippet:

function saveDispatchedMessages(code: number, data: ArrayBuffer, userID: string) {

    const matchState = [
        {
            code: code,
            data: data,
        },
]

    var write: nkruntime.StorageWriteRequest = {
        collection: "MatchStates",
        key: "Dispatched",
        value: matchState,
        userId: userID,
        permissionRead: 1,
        permissionWrite: 0,
    }
}

If the key, collection and user_id are always the same, you’re only really storing the most recent message.

The storage engine also does not guarantee ordering of the read objects when using the listing API, you’d need to store the messages all within the same object in an array to ensure that the ordering is kept, otherwise you’d need some sort of seq number in the object/message and the client would be responsible for buffering and ordering the messages in-memory before applying them.

Hope this helps