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.
- Versions: Nakama 3.5, Docker, Godot client
- Server Framework Runtime language: TS/JS