Page 1 of 1

Sending notifications before first player action

Posted: 07 October 2020, 22:36
by jarhead271
Hi,
I am trying to send notifications to players, which don't seem to be making it to the client browsers.

I have a simple state machine:

Code: Select all

    // The initial state. Please do not modify.
	1 => array(
		"name" => "gameSetup",
		"description" => "",
		"type" => "manager",
		"action" => "stGameSetup",
		"transitions" => array( "" => 10 )
	),
    
    // Note: ID=2 => your first state

	10 => array(
		"name" => "roundSetup",
		"type" => "game",
		"action" => "stRoundSetup",
		"transitions" => array( "startRound" => 20 )
	),

	20 => array(
		"name" => "playerTurn",
		"description" => clienttranslate('${actplayer} must place a token'),
		"descriptionmyturn" => clienttranslate('${you} must place a token'),
		"type" => "activeplayer",
		"possibleactions" => array( "playToken" ),
		"transitions" => array( "playToken" => 25 )
	),
So after "gameSetup", I am moving into state "roundSetup". The function for roundSetup is:

Code: Select all

	function stRoundSetup()
	{
		// This doesn't seem to work
		self::debug("In stRoundSetup");
				
		// The message 'Round # has begun' IS showing up in the player notification area
		self::notifyAllPlayers( "roundSetup", clienttranslate( 'Round # has begun!' ), array() );
		
		// This is working
		$this->gamestate->nextState('startRound');

	}
First off, the debug message is not showing up in the BGA request log. I know that logging is not visible if written from the constructor or gameSetup, but we are in a different state by this point. I expected it to work once we are out of the gameSetup state, but I guess I am mistaken.

I'm unsure if the notifyAllPlayers call is working. I do see the message 'Round # has begun!' for each player, in the notification area, but the commands in my .js function, notif_roundSetup, don't appear to be executing:

Code: Select all

		notif_roundSetup: function(notif)
		{
			//Neither of these commands are working
			console.log('notif_roundSetup');
			this.testVar = "WORKING";
		},
The plan for the roundSetup state was to inform each player which set of tokens they have in their hand. This needs to happen each round, before the first player acts. If my current approach is not correct, how should I handle this situation? Maybe include the initial set of tokens for each player in gameDatas instead of relying on notifications?

Thank you!

Re: Sending notifications before first player action

Posted: 07 October 2020, 23:59
by RicardoRix
Yes, use the gamedatas.
Which you'll have to do anyway because anyone can press F5 at any time.
Something about notifications not working until after the setup.

Re: Sending notifications before first player action

Posted: 10 October 2020, 02:49
by Victoria_La
I just checked my game and I do have same kind of state setup, where first state is game state and it is upkeep, and it does send notifications and it works.
Make sure at the end of game setup you set active player. Notification are batched and not send until first player state, but I am not sure
what happens when no active player set