Hearts Tutorial, how to implement onCardClick function?

Game development with Board Game Arena Studio
Post Reply
User avatar
kingdedede745
Posts: 18
Joined: 25 June 2022, 04:18

Hearts Tutorial, how to implement onCardClick function?

Post by kingdedede745 »

I'm going through the hearts tutorial (https://en.doc.boardgamearena.com/Tutor ... teractions), and I'm at the Client Server interactions section.

When I change

Code: Select all

this.handStock.onCardClick = (card) => {
        this.tableauStocks[card.location_arg].addCards([card]);
     };
to

Code: Select all

this.handStock.onCardClick = (card) => {
        this.onCardClick(card);
     };
as instructed, I get the following error:

Javascript error:
Uncaught TypeError: this.onCardClick is not a function

I've checked the GitHub repo for the tutorial and it's using a different template. My JavaScript file has two classes: a PlayerTurn class and a Game class. The onCardClick function is defined in the PlayerTurn class, which I'm pretty sure I didn't touch since I started the tutorial. Mine doesn't have

Code: Select all

define([
    "dojo","dojo/_base/declare",
    "ebg/core/gamegui",
    "ebg/counter",
    "ebg/stock"
],
at the top.

I have tried changing the location of the onCardClick function to a couple different places but nothing works.

Can anyone help?
User avatar
RichardSPeters
Posts: 18
Joined: 27 August 2021, 23:14

Re: Hearts Tutorial, how to implement onCardClick function?

Post by RichardSPeters »

Stuck in exactly same situation so if you do figure out a solution would be great if you could post it in this thread. :D

FYI - my next plan is to try and find a game that uses the "ClassName class" type framework rather than the "dojo","dojo/_base/declare" type framework and see if can locate similar functionality.

Ok - so I had a look at various projects (see https://studio.boardgamearena.com/projects) and found a few that use the "ClassName class" type framework. They are:
  • spike
  • fate
  • drako
  • satchelquest
  • timebarons
User avatar
RichardSPeters
Posts: 18
Joined: 27 August 2021, 23:14

Re: Hearts Tutorial, how to implement onCardClick function?

Post by RichardSPeters »

kingdedede745 wrote: 24 February 2026, 05:01 I'm going through the hearts tutorial (https://en.doc.boardgamearena.com/Tutor ... teractions), and I'm at the Client Server interactions section....

Can anyone help?
Try this

replace

Code: Select all

    this.handStock.onCardClick = (card) => {
      this.tableauStocks[card.location_arg].addCards([card]);
    };
with

Code: Select all

    this.handStock.onCardClick = (card) => {
      {
        console.log("onCardClick : card ", card);
        console.log("onCardClick : namestate ", this.gamedatas.gamestate.name);
        if (!card) return; // hmm - should never happen
        switch (this.gamedatas.gamestate.name) {
          case "PlayerTurn":
            // Can play a card
            this.bga.actions.performAction("actPlayCard", { cardId: card.id });
            break;
          case "GiveCards":
            // Can give cards TODO
            break;
          default: {
            this.handStock.unselectAll();
            break;
          }
        }
      }
    };
which does get triggered when you click on a Card
Post Reply

Return to “Developers”