How to pickup a card from the deck and put it in your hand

Game development with Board Game Arena Studio
JCase16
Posts: 38
Joined: 26 June 2015, 19:07

How to pickup a card from the deck and put it in your hand

Postby JCase16 » 16 February 2018, 00:39

So I'm modifying the hearts tutorial that Victoria_La built. Thanks again! I'm trying to cause a player to pickup cards from the deck when a card is played. here is the playCard function. How could I modify this to pick up 2 cards from the deck?

Code: Select all

    function playCard($card_id) {
        self::checkAction("playCard");
        $player_id = self::getActivePlayerId();
        $this->cards->moveCard($card_id, 'cardsontable', $player_id);
        // XXX check rules here
        $currentCard = $this->cards->getCard($card_id);

        $currentTrickColor = self::getGameStateValue( 'trickColor' ) ;
        if( $currentTrickColor == 0 )
           self::setGameStateValue( 'trickColor', $currentCard['type'] );

        // And notify
        self::notifyAllPlayers('playCard', clienttranslate('${player_name} plays ${value_displayed} ${color_displayed}'), array (
                'i18n' => array ('color_displayed','value_displayed' ),'card_id' => $card_id,'player_id' => $player_id,
                'player_name' => self::getActivePlayerName(),'value' => $currentCard ['type_arg'],
                'value_displayed' => $this->values_label [$currentCard ['type_arg']],'color' => $currentCard ['type'],
                'color_displayed' => $this->colors [$currentCard ['type']] ['name'] ));
        // Next player
       

JCase16
Posts: 38
Joined: 26 June 2015, 19:07

Re: How to pickup a card from the deck and put it in your hand

Postby JCase16 » 16 February 2018, 19:35

So figured out how to add cards with the pickCards funtion. However, the cards are added but they are not displayed until I refresh the page. Any idea why this code is not working to notify the player of the new cards? I thought I followed the manual on this.

Code: Select all

$cards = $this->cards->pickCards(2, 'deck', $player_id);
        self::notifyPlayer( $player_id, 'newCard', '', array(
            'cards' => $cards
        ) );

User avatar
fa81
Posts: 20
Joined: 25 November 2016, 16:35

Re: How to pickup a card from the deck and put it in your hand

Postby fa81 » 16 February 2018, 19:39

You need a function on the JavaScript side that acts on the notification and moves the card (usually using the Stock component). It does not happen automagically.

User avatar
fa81
Posts: 20
Joined: 25 November 2016, 16:35

Re: How to pickup a card from the deck and put it in your hand

Postby fa81 » 16 February 2018, 19:43

See Hearts tutorial, look for this code:

Code: Select all

notif_playCard : function(notif) {
            // Play a card on the table
            this.playCardOnTable(notif.args.player_id, notif.args.color, notif.args.value, notif.args.card_id);
        },

http://en.doc.boardgamearena.com/Tutori ... teractions

JCase16
Posts: 38
Joined: 26 June 2015, 19:07

Re: How to pickup a card from the deck and put it in your hand

Postby JCase16 » 16 February 2018, 21:07

So I figured this out after hunting for a while and messing with stuff. I thought notifcations were default. They are and they aren't. You have to subscribe to and build your own in the JS file.

I added this in the JS file:

Code: Select all

dojo.subscribe('newCards', this, "notif_newCards");


I added this in the JS file:

Code: Select all

notif_newCards: function(notif) {
            var player_id = notif.args.player_id;
            var cards = notif.args.cards;
            console.log(cards);
            // Draw cards
            for (var i = 0; i < cards.length; i++) {
                var card = cards[i];
                var color = card.type;
                var value = card.type_arg;
                this.playerHand.addToStockWithId(this.getCardUniqueId(color, value), card.id);
                console.log(this.playerHand);
            }
        },


And then this piece of code started working properly:

Code: Select all

$cards = $this->cards->pickCards(2, 'deck', $player_id);
        self::notifyPlayer( $player_id, 'newCards', '', array(
            'cards' => $cards
        ) );

User avatar
Victoria_La
Posts: 299
Joined: 28 December 2015, 20:55

Re: How to pickup a card from the deck and put it in your hand

Postby Victoria_La » 18 February 2018, 21:19

If you still talking about hearts tutorial it was in stNewHand function, when player picks new hidden cards, you send private notification


Return to “Developers”

Who is online

Users browsing this forum: No registered users and 5 guests