Page 1 of 1

[Solved] Updating non active player screens via notifications does not work

Posted: 05 March 2022, 09:26
by _Maestro_
Hi,

I am still relatively at the start of my development and I have just programmed the draft section where people can choose one by one their cards.
On the active player screen, everything works.
But on the non-active player screen nothing happens. The card the other player choses, is still visible.
I have read you need to do these updates via notifications.

So I tried implementing this and it does give the notification update etc, but nothing happens on the screen of the inactive player.

On php side the function which is performed on the active screen:

Code: Select all

    function playCard($card_id) {
        self::checkAction("playCard");
        $player_id = self::getActivePlayerId();
        $this->navCards->moveCard($card_id, 'hand', $player_id);
        $currentCard = $this->navCards->getCard($card_id);
        $this->gamestate->nextState('nextPlayer');
            self::notifyAllPlayers( "playCard", clienttranslate( '${player_name} takes a card' ), array(
                'player_id' => $player_id,
                'player_name' => self::getActivePlayerName(),
                'card_id' => $this->navCards->getCard($card_id)
            ) );
    }
This is the notification in JS. I only want to remove the card from the deck called navDeck.

Code: Select all

        setupNotifications: function()
        {
            console.log( 'notifications subscriptions setup' );
            dojo.subscribe( 'playCard', this, "notif_playCard" );        
        },  
         notif_playCard: function( notif )
        {
         console.log(notif.args.card_id);
         this.navDeck.removeFromStockById(notif.args.card_id)
     	 this.navDeck.updateDisplay();
The console log on the notif.args is:
id: "12"
location: "hand"
location_arg: "2363192"
type: "0"
type_arg: "11"

As you can see the card is moved to "hand" instead of "deck". Is this the reason why I can no longer remove the card from the deck on the inactive screen?

What can i do to remove the card also form the other screens (without reloading the screen)?

Thanks Maurice

Re: Updating non active player screens via notifications does not work

Posted: 05 March 2022, 15:18
by robinzig
I don't see any reason why this would work in the active player's browser but not that of the other players.

Are you sure you refreshed all the other browsers after making this code change, before testing it?

Re: Updating non active player screens via notifications does not work

Posted: 05 March 2022, 16:19
by RicardoRix
Things I've noticed:

php getCard() looks like card_id is actually a card. so might actually come out as notif.args.card_id.id the other end.
JS there is no ; on the end of one of the statements.
JS there is no need to updateDIsplay() in this instance.

why do this $currentCard = $this->navCards->getCard($card_id); if later you don't use $currentCard ?

If it's working for the active player, does that mean you are removeFromStockById() somewhere else?
This should be done for all players in the notification handler.

If you're drafting, is this meant to be multiplayer mode, is this not private info until the cards get passed to the player?

I have a problem with your naming convections, card_id is an id not a card. PlayCard is really DraftCard.

Re: Updating non active player screens via notifications does not work

Posted: 05 March 2022, 20:07
by _Maestro_
Thanks for your reply. In a different part of the code i indeed removed the card already. By deleting that part and let the notification do its work it got resolved.

On the naming convention... i am using pieces of code now from the tutorials. Will clean that up soon.