Issue with javascript array handling

I am writing an authoritarian card game. Im using typescript to write the server side logic. My issue is that in the first round everything works as expected. But when i begin a new round afterwards in the same match, the array stops working as expected. When i splice the array it doesnt shorten it, instead it inserts null values at the end. It also doesn’t add it to the players hand.
The code:

protected static dealCardsToPlayer(state: BaseCardGameState, playerIndex: number, numberOfCards: number, broadcast: boolean = true) {
    const playerHand = state.players[playerIndex].hand
    const newCards = state.talon.splice(0, numberOfCards)
    playerHand.push(...newCards)
    ...

The game state:
Before dealing:

"talon": [
    {
      "suit": 2,
      "rank": 4
    },
    {
      "suit": 2,
      "rank": 2
    },
...
    {
      "suit": 2,
      "rank": 10
    }
  ],
"players": [
    {
      "id": "c54ea6f6-e406-4269-aef0-4f16276dde6b",
      "points": 0,
      "hand": [],
      "team": 0,
      "isReady": false
    },
    {
      "isReady": false,
      "id": "56222023-b567-40c8-9c68-f246e5adc817",
      "points": 0,
      "hand": [],
      "team": 1
    }
  ],

After dealing cards:

"talon": [
    {
      "suit": 3,
      "rank": 3
    },
    {
      "suit": 1,
      "rank": 4
    },
    {
      "suit": 1,
      "rank": 11
    },
    {
      "rank": 11,
      "suit": 3
    },
    {
      "suit": 3,
      "rank": 2
    },
    {
      "suit": 2,
      "rank": 11
    },
    {
      "suit": 2,
      "rank": 3
    },
    {
      "suit": 0,
      "rank": 2
    },
    {
      "suit": 3,
      "rank": 10
    },
    {
      "suit": 2,
      "rank": 10
    },
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null,
    null
  ],
"players": [
    {
      "id": "c54ea6f6-e406-4269-aef0-4f16276dde6b",
      "points": 0,
      "hand": [],
      "team": 0,
      "isReady": false
    },
    {
      "id": "56222023-b567-40c8-9c68-f246e5adc817",
      "points": 0,
      "hand": [],
      "team": 1,
      "isReady": false
    }
  ],

The crazy part is all these functions work in the first round and somehow stop working when the next round begins.

  1. Versions: Nakama 3.5, Docker, Godot client
  2. Server Framework Runtime language: TS/JS

Hello @MrDog,

There’s a few caveats around the JS runtime due to how Goja (the JS engine written in Go) works - we have some upcoming improvements that should resolve these but they’re still experimental so we can’t promise they’ll be out in the next release.

As a workaround, I think that if you create a new array and push to that instead of the existing one, it should work as expected.

Best.

Thanks for the info, I will try it with a new array. Would you know when the next version will approximately release?

Update: I fixed the issue by building my own docker image of this pull request: Javascript runtime improvements by sesposito · Pull Request #1323 · heroiclabs/nakama · GitHub. And now everything works correctly!

That’s good to know, thanks for the update!

Given that the PR is still in draft and there’s some more testing to do, if you run into any issues let me know, could be useful information :slight_smile:

Best