Page 1 of 1

registered notify method not working

Posted: 28 September 2018, 03:47
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.

Re: registered notify method not working

Posted: 28 September 2018, 11:00
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

Re: registered notify method not working

Posted: 01 October 2018, 02:01
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 )
    ),

Re: registered notify method not working

Posted: 01 October 2018, 08:49
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