[Solved]How to select cards?

Game development with Board Game Arena Studio
Post Reply
User avatar
JudgeWhyMe
Posts: 36
Joined: 08 August 2012, 17:14

[Solved]How to select cards?

Post by JudgeWhyMe »

Hello

I am using the BgaCards module.

Server send to client a hand of cards, cards selected, and card selectable in this hand (via gamedatas)
gamedatas.hand
{
3 : {id: '3', type: '1_Pro', type_arg: '3', location: 'R&D_2413802', location_arg: '0'}
7 : {id: '7', type: '3_Cor', type_arg: '7', location: 'R&D_2413802', location_arg: '0'}
8 : {id: '8', type: '3_Cor', type_arg: '8', location: 'R&D_2413802', location_arg: '0'}
10 : {id: '10', type: '0_Har', type_arg: '10', location: 'R&D_2413802', location_arg: '0'}
11 : {id: '11', type: '0_Har', type_arg: '11', location: 'R&D_2413802', location_arg: '0'}
12 : {id: '12', type: '0_Har', type_arg: '12', location: 'R&D_2413802', location_arg: '0'}
}

gamedatas.selectable
{
10 : {card_id: '10', card_type: '0_Har', card_type_arg: '10', card_location: 'R&D_2413802', card_location_arg: '0'}
12 : {card_id: '12', card_type: '0_Har', card_type_arg: '12', card_location: 'R&D_2413802', card_location_arg: '0'}
}

gamedatas.selected
{
7 : {card_id: '7', card_type: '3_Cor', card_type_arg: '7', card_location: 'R&D_2413802', card_location_arg: '0'}
8 : {card_id: '8', card_type: '3_Cor', card_type_arg: '8', card_location: 'R&D_2413802', card_location_arg: '0'}
11 : {card_id: '11', card_type: '0_Har', card_type_arg: '11', card_location: 'R&D_2413802', card_location_arg: '0'}
}


I can display the hand of cards:
for (const cardId in this.gamedatas.hand)
{
let card = { id: parseInt(this.gamedatas.hand[cardId]['id']) };
card.type = this.gamedatas.hand[cardId]['type'];
card.type_arg = this.gamedatas.hand[cardId]['type_arg'];
card.tooltip = cardId;
cards.push(card);
}
this.playerHand.addCards(cards);

I managed to set the selectable cards and the unselectable ones

let selectableCards = this.playerHand.getCards().filter((card) => Object.keys(this.gamedatas.selectable).find((element) => element==card.id));
this.playerHand.setSelectableCards(selectableCards);

Bu I cant find how to show the selected cards
I see in the documentation there is a metho to select one card (https://x.boardgamearena.net/data/game- ... selectcard)
Do you have to select cards one by one? There is no method to select several cards at once?

I tried this method in a loop, but the cards does not appear as selected
for (const selectedCardId in this.gamedatas.selected)
{ this.playerHand.selectCard(this.playerHand.getCards().filter((card) => card.id == selectedCardId)); }

Thanks for any help
Last edited by JudgeWhyMe on 24 March 2026, 11:22, edited 1 time in total.
CagedEye
Posts: 8
Joined: 24 February 2025, 06:41

Re: How to select cards?

Post by CagedEye »

Yes. You have to select the cards one by one. However, you first need to call setSelectionMode. Something like:
this.playerHand.setSelectionMode('multiple');
User avatar
JudgeWhyMe
Posts: 36
Joined: 08 August 2012, 17:14

Re: How to select cards?

Post by JudgeWhyMe »

Thanks. I did set the selection mode:
this.playerHand.setSelectionMode('multiple');

But the cards are still not selected
User avatar
RicardoRix
Posts: 2540
Joined: 29 April 2012, 23:43

Re: How to select cards?

Post by RicardoRix »

from memory you get a css class added 'selected' to the cards selected. It's up to you to define that. Although, perhaps by default I thought you might also get a red border, from a css inline style (?). Either way try and use the chrome F12 inspect element.
User avatar
JudgeWhyMe
Posts: 36
Joined: 08 August 2012, 17:14

Re: How to select cards?

Post by JudgeWhyMe »

Thanks for your answers.

I found the issue. In setSelectableCards, I used as a parameter an array of one card object instead of just the card object.
Post Reply

Return to “Developers”