registered notify method not working

Game development with Board Game Arena Studio
Post Reply
User avatar
AmadanNaBriona
Posts: 43
Joined: 17 March 2018, 18:52

registered notify method not working

Post by AmadanNaBriona »

More n00b questions:

A notify method I registered does not seem to ever get invoked.

In my game.php file:

Code: Select all


    function stAssignRoles() {
		$this->cards->moveAllCardsInLocation(null, 'deck');
		$this->cards->moveAllCardsInLocation(null, 'doordeck');
		$this->cards->shuffle('deck');
		$this->cards->shuffle('doordeck');

        $players = self::loadPlayersBasicInfos();
        foreach( $players as $player_id => $player ) {
            $door = $this->cards->pickCard( 'doordeck', $player_id );
     //Notify player of his Role
            self::notifyPlayer( $player_id, 'newRole', '', array( 
                'hand' => $door
            ) );
        }
		
	$cards = $this->cards->pickCardsForLocation(4, 'deck', 'cluecarddisplay');

        $this->gamestate->nextState( "" );
	}

In my .js file:

Code: Select all

        setupNotifications: function()
        {
            console.log( 'notifications subscriptions setup' );
            // here, associate your game notifications with local methods
            dojo.subscribe( 'newRole', this, 'notif_newRole' );
        },  
and

Code: Select all

        /**
         * Called when a player is a given a new Door (role) card
         */
        notif_newRole: function( notif ) {
            console.log("notifying of new role");
            throw new BgaVisibleSystemException ( "This never happens, but it should!"); 
        },


The stAssignRoles() method does execute, but I never see the notification get triggered.
vincentt
Posts: 247
Joined: 01 September 2017, 17:25

Re: registered notify method not working

Post by vincentt »

Hello,

Is it on your first method? Because if so you shoud consider that it has been already called but the JS was not "up" at this point. So the info shoudl be available through the GetAllDatas method

I hope I am clear

Vincent
User avatar
AmadanNaBriona
Posts: 43
Joined: 17 March 2018, 18:52

Re: registered notify method not working

Post by AmadanNaBriona »

vincentt wrote:Hello,

Is it on your first method? Because if so you shoud consider that it has been already called but the JS was not "up" at this point. So the info shoudl be available through the GetAllDatas method

I hope I am clear

I'm not entirely clear. The stAssignRoles method is assigned to the first state the game enters after game setup.

From my states.inc.php file:

Code: Select all

    // The initial state. Please do not modify.
    STATE_SETUP => array(
        "name" => "gameSetup",
        "description" => clienttranslate("Game setup"),
        "type" => "manager",
        "action" => "stGameSetup",
        "transitions" => array( "" => STATE_ASSIGN_ROLES )
    ),
    
    // Assign/Switch Roles between Collector and Guesser
    STATE_ASSIGN_ROLES => array(
    		"name" => "assignRoles",
    		"description" => clienttranslate('Reassigning roles'),
    		"descriptionmyturn" => clienttranslate('Reassigning roles'),
    		"type" => "game",
    		"action" => "stAssignRoles",
         "updateGameProgression" => true,   
    		"transitions" => array( "" => STATE_PLAYER_ACTION )
    ),
vincentt
Posts: 247
Joined: 01 September 2017, 17:25

Re: registered notify method not working

Post by vincentt »

Hi,

So if it is the first state thats what I am talking about.
When you start your table, all the state are automatically followed before "starting" the browser. Therefore, no notification is launched (or at least received) and when the web page is displayed, you should have everything setup through GetAllDatas.

If in this state, after a user action (click or other), you trigger the same notif, it should be displayed

Vincent
Post Reply

Return to “Developers”