Page 1 of 1
Early notifications
Posted: 22 December 2014, 22:10
by sparr
Notifications sent between the game start (setupNewGame) and the end of the "action" method of the first active state will never reach their destination.
If I want some notifications sent before the first player's turn to appear to all the players, should I just insert a dummy state in betwen the start and my first real state?
PS: What makes a state "active"?
Re: Early notifications
Posted: 22 December 2014, 23:42
by Een
Hi,
You can use notifyAllPlayers in the game setup, for example at the end of setupNewGame(). Just tried it for some game, and it works.
State number 2 is activated after the game setup (which is state number 1); other states are activated when you apply the proper transition (as defined in the states file) to go from one state to another with $this->gamestate->nextState( "transition" );
Cheers,
Een
Re: Early notifications
Posted: 23 December 2014, 16:46
by sparr
Code: Select all
// The initial state. Please do not modify.
1 => array(
"name" => "gameSetup",
"description" => clienttranslate("Game setup"),
"type" => "manager",
"action" => "stGameSetup",
"transitions" => array( "" => 10 )
),
// new hand. collect cards, shuffle, deal, identify start player
10 => array(
"name" => "newHand",
"description" => "",
"type" => "game",
"action" => "stNewHand",
"updateGameProgression" => true,
"transitions" => array( "playerTurnStart" => 20, "gameEnd" => 99 )
),
in stNewHand() I have this:
Code: Select all
self::notifyAllPlayers( 'playCard',
clienttranslate('${player_name} starts with ${color_displayed} ${number_displayed} in their palette'),
array(
Now, all the effects of notif_newHand in my javascript do work. So the gameplay/logic isn't broken. What doesn't work is the display of the "... starts with ... ... in their palette" text in the game log. It works on every hand other than the first one of the game.
Re: Early notifications
Posted: 23 December 2014, 22:16
by Een
Yes, I was suggesting that you notify at the end of stGameSetup, but in your case your new hand has not yet been drawn.
So adding an extra 'dummy' state between 1 and 10 seems indeed the best solution.
I usually define "nextPlayer" as my second state (which doesn't need notifications), so I have never run into that notification trouble myself.
Re: Early notifications
Posted: 24 December 2014, 15:39
by sparr
Code: Select all
// The initial state. Please do not modify.
1 => array(
"name" => "gameSetup",
"description" => clienttranslate("Game setup"),
"type" => "manager",
"action" => "stGameSetup",
"transitions" => array( "" => 5 )
),
// A dummy state, to fix a bug with notification text in the first state after 1.
5 => array(
"name" => "dummyStart",
"description" => clienttranslate("Game setup"),
"type" => "game",
"action" => "stDummyStart",
"transitions" => array( "newHand" => 10 )
),
// new hand. collect cards, shuffle, deal, identify start player
10 => array(
"name" => "newHand",
"description" => "",
"type" => "game",
"action" => "stNewHand",
"updateGameProgression" => true,
"transitions" => array( "playerTurnStart" => 20, "gameEnd" => 99 )
),
Code: Select all
function stDummyStart()
{
$this->gamestate->nextState( "newHand" );
}
function stNewHand()
{
...
// Notify all players about starting palettes
//FIXME: the 'starts with' text doesn't appear for the first hand of a game
self::notifyAllPlayers( 'playCard',
clienttranslate('${player_name} starts with ${color_displayed} ${number_displayed} in their palette'),
array(
Still no dice. The "... starts with ..." text doesn't appear in the players' game logs.
Re: Early notifications
Posted: 24 December 2014, 21:25
by Een
Hmm. Maybe a dummy notification in stDummyStart in case only the first notification gets lost ?

No other idea without plunging really deep.
Re: Early notifications
Posted: 25 December 2014, 01:37
by sparr
The notifyAllPlayers in question here is inside a loop. It runs 2-4 times, so it's not just the first instance getting lost.
It would be helpful if I knew, for sure, what triggered the "notifications start working" behavior. I've tried putting an activeplayer state before newHand, but that doesn't seem to fix it, either. Do I need to put in a state where the player actually does something?