How can I send different state descriptions to different players

Game development with Board Game Arena Studio
Post Reply
User avatar
Brederic
Posts: 26
Joined: 29 January 2013, 00:06

How can I send different state descriptions to different players

Post by Brederic »

I have a multiactive state in which all but one of the players are choosing cards to give to the last player. I want the game interface to tell the players giving cards. "You must choose a card to give to PlayerX" and PlayerX to see "Some players must choose a card to give to you."

PlayerX is getting the right message, but the other players are seeing, "You must choose a card to give to you."

Do you have any ideas of how to get this right?

Thanks in advance for your help!
Brederic

Here are the details:

I have a multiactive player state (from states.inc.php)

Code: Select all

 
 30 => array(       
        "name" => "giveCards",
        "description" => clienttranslate('Some players must choose a card to give to ${direction}'),
        "descriptionmyturn" => clienttranslate('${you} must choose a card to give to ${direction}'),
        "type" => "multipleactiveplayer",
        "action" => "stGiveCards",
        "args" => "argGiveCards",
        "possibleactions" => array( "giveCards" ),
        "transitions" => array( "giveCards" => 31 )        
    ), 
    
I am filling in ${direction} with this method in game.php:

Code: Select all

function argGiveCards()
    {
        $me = self::getCurrentPlayerId();
        self::trace('argGiveCards $me='.$me);
        $players = self::loadPlayersBasicInfos();   
        $player_id = self::getGameStateValue( 'playerBuildingSentence' );
        $player_name = $players[ $player_id ]['player_name'];

        if ($me == $player_id) {
            $direction = clienttranslate('you');
        } else {
            $direction = $player_name;
        }
        self::trace('argGiveCards $direction='.$direction);
        return array(
            "i18n" => array( 'direction'),
            "direction" => $direction
        );
    }
   
In the game interface the playerBuildingSentence sees "Some players must choose a card to give to you." as desired, but the other players see: "You must choose a card to give to you".

In the logs, it appears argGiveCards() is only called once:
27/10 12:38:55 [info] [M] [2298429/BrentP4] /rememberwhen/rememberwhen/chooseRole.html?choice=1&lock=8388b309-73a6-4787-8b91-1d0ea621e2d9&table=32859&testuser=2298429&dojo.preventCache=14775647323462
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] setTable2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] nextState with action: 'chooseRole'2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] jump to state 302
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.53 UPDATE global SET global_value='30' WHERE global_id='1' 2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4]argGiveCards $me=22984292
27/10 12:38:55 [info] [T32859] [2298429/BrentP4]argGiveCards $direction=you2

27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.55 SELECT player_id, player_is_multiactive FROM player LOCK IN SHARE MODE 2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] New game state: 'giveCards'2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.54 UPDATE global SET global_value=UNIX_TIMESTAMP(NOW()) WHERE global_id='0'2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.53 SELECT player_id, player_is_multiactive FROM player LOCK IN SHARE MODE 2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.67 UPDATE player SET player_start_reflexion_time=NULL2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.57 UPDATE player SET player_is_multiactive='1' WHERE 12
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.54 SELECT player_id, player_is_multiactive FROM player LOCK IN SHARE MODE 2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.54 UPDATE player SET player_is_multiactive='0' WHERE player_id='2298429' 2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.51 SELECT player_id, player_is_multiactive FROM player LOCK IN SHARE MODE 2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] action player number = 32
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] after jump to nextState2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] Sending notifications2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.79 INSERT INTO gamelog (gamelog_move_id, gamelog_private, gamelog_time, gamelog_player, gamelog_current_player, gamelog_notification)
VALUES
( '4', '0', NOW(), NULL,'2298429', 'a:5:{i:0;a:5:{s:4:\"time\";s:5:\"10:38\";s:3:\"uid\";s:13:\"5811d93f2729a\";s:4:\"type\";s:10:\"chooseRole\";s:3:\"log\";s:42:\"${player_name} is acting as a ${role_name}\";s:4:\"args\";a:5:{s:4:\"i18n\";a:2:{i:0;s:15:\"color_displayed\";i:1;s:15:\"value_displayed\";}s:9:\"player_id\";s:7:\"2298429\";s:11:\"player_name\";s:7:\"BrentP4\";s:9:\"role_name\";s:4:\"Hero\";s:6:\"choice\";s:1:\"1\";}}i:1;a:5:{s:4:\"time\";s:5:\"10:38\";s:3:\"uid\";s:13:\"5811d93f28cc3\";s:4:\"type\";s:14:\"leaveGameState\";s:3:\"log\";s:0:\"\";s:4:\"args\";a:10:{s:4:\"name\";s:10:\"chooseRole\";s:11:\"description\";s:32:\"${actplayer} must choose a role.\";s:17:\"descriptionmyturn\";s:26:\"${you} must choose a role.\";s:4:\"type\";s:12:\"activeplayer\";s:15:\"possibleactions\";a:1:{i:0;s:10:\"chooseRole\";}s:11:\"transitions\";a:1:{s:10:\"chooseRole\";i:30;}s:13:\"active_player\";s:7:\"2298429\";s:12:\"admin_player\";s:7:\"2298425\";s:4:\"args\";N;s:9:\"reflexion\";a:2:{s:4:\"move\";a:2:{s:5:\"value\";i:216;s:5:\"total\";i:240;}s:5:\"total\";a:4:{i:2298429;i:-66981;i:2298428;s:3:\"300\";i:2298425;s:3:\"300\";i:2298427;s:3:\"300\";}}}}i:2;a:5:{s:4:\"time\";s:5:\"10:38\";s:3:\"uid\";s:13:\"5811d93f2a9f4\";s:4:\"type\";s:15:\"gameStateChange\";s:3:\"log\";s:0:\"\";s:4:\"args\";a:12:{s:4:\"name\";s:9:\"giveCards\";s:11:\"description\";s:55:\"Some players must choose a card to give to ${direction}\";s:17:\"descriptionmyturn\";s:49:\"${you} must choose a card to give to ${direction}\";s:4:\"type\";s:20:\"multipleactiveplayer\";s:6:\"action\";s:11:\"stGiveCards\";s:4:\"args\";a:2:{s:4:\"i18n\";a:1:{i:0;s:9:\"direction\";}s:9:\"direction\";s:3:\"you\";}s:15:\"possibleactions\";a:1:{i:0;s:9:\"giveCards\";}s:11:\"transitions\";a:1:{s:9:\"giveCards\";i:31;}s:13:\"active_player\";s:7:\"2298429\";s:12:\"admin_player\";s:7:\"2298425\";s:9:\"reflexion\";a:2:{s:4:\"move\";a:2:{s:5:\"value\";i:216;s:5:\"total\";i:240;}s:5:\"total\";a:4:{i:2298429;i:-66981;i:2298428;s:3:\"300\";i:2298425;s:3:\"300\";i:2298427;s:3:\"300\";}}s:11:\"multiactive\";a:0:{}}}i:3;a:5:{s:4:\"time\";s:5:\"10:38\";s:3:\"uid\";s:13:\"5811d93f2b98b\";s:4:\"type\";s:29:\"gameStateMultipleActiveUpdate\";s:3:\"log\";s:0:\"\";s:4:\"args\";a:4:{i:0;s:7:\"2298429\";i:1;s:7:\"2298428\";i:2;s:7:\"2298425\";i:3;s:7:\"2298427\";}}i:4;a:6:{s:4:\"time\";s:5:\"10:38\";s:3:\"uid\";s:13:\"5811d93f2e9e3\";s:4:\"type\";s:29:\"gameStateMultipleActiveUpdate\";s:3:\"log\";s:0:\"\";s:4:\"args\";a:3:{i:0;s:7:\"2298428\";i:1;s:7:\"2298425\";i:2;s:7:\"2298427\";}s:9:\"lock_uuid\";s:36:\"8388b309-73a6-4787-8b91-1d0ea621e2d9\";}}')2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] 0.89 SELECT COALESCE( gamelog_player, 0 ), MAX( gamelog_packet_id )
FROM gamelog
WHERE gamelog_packet_id<9
GROUP BY gamelog_player2
27/10 12:38:55 [info] [T32859] [2298429/BrentP4] DB commit: action validate2
27/10 12:38:55 [notice] [T32859] [2298429/BrentP4] OK-0 118 d27 c11 e0 I37 A77 V1 T1 /rememberwhen/rememberwhen/chooseRole.html?choice=1&lock=8388b309-73a6-4787-8b91-1d0ea621e2d9&table=32859&testuser=2298429&dojo.preventCache=1477564732346
User avatar
marcgenesis
Posts: 36
Joined: 27 August 2015, 01:53

Re: How can I send different state descriptions to different players

Post by marcgenesis »

Hi Brederic,

Here's what I would do: Since argGiveCards() is called only once, I would grab the data I need in one run. What do we need? Well we need the name of the player who will receive the cards. Do we need to know "me"? No because "me" is "you"... :)

Code: Select all

function argGiveCards()
    {
        $players = self::loadPlayersBasicInfos();   
        $player_id = self::getGameStateValue( 'playerBuildingSentence' );
        $player_name = $players[ $player_id ]['player_name'];

        $player_color = $players[ $player_id ]['player_color'];
        $direction = $player_name;
        
        self::trace('argGiveCards $direction='.$direction);
        return array(
            "i18n" => array( 'direction'),
			"player_color" => $player_color,
            "direction" => $direction
        );
    }
As you can see, I got rid of the if and I am just supplying the player_name for your variable "direction". If you notice, I am also supplying the "direction" player_color.

In your state.inc.php, I would change it to the following:

Code: Select all

30 => array(       
        "name" => "giveCards",
        "description" => clienttranslate('Some players are choosing cards to give to <span style="color: #${player_color};">you</span>.'),
        "descriptionmyturn" => clienttranslate('${you} must choose a card to give to <span style="color: #${player_color};">${direction}</span>'),
        "type" => "multipleactiveplayer",
        "action" => "stGiveCards",
        "args" => "argGiveCards",
        "possibleactions" => array( "giveCards" ),
        "transitions" => array( "giveCards" => 31 )       
    ), 
What it does is display "Some players are choosing cards to give to you." to the player that is not active, and displaying "You must choose a card to give to receiver." to the active players.

As you can probably guess, by applying a span to the "you" or the "direction" with the color styled, you get the "you" and the receiver name in the color of that player (supplied by your argGiveCards function).

Active player player: You must choose a card to give to marcgenesis0
Receiver: Some players are choosing cards to give to you.

Cheers, let me know if you need further help.
User avatar
Brederic
Posts: 26
Joined: 29 January 2013, 00:06

Re: How can I send different state descriptions to different players

Post by Brederic »

This is an improvement, because all the players initially see the right message. Adding the player color was nice, too.

But after a player chooses a card and sends it, his message changes from
You must choose a card to give to BrentP0
to
Some players are choosing cards to give to you.

It should say
Some players are choosing cards to give to BrentP0
User avatar
marcgenesis
Posts: 36
Joined: 27 August 2015, 01:53

Re: How can I send different state descriptions to different players

Post by marcgenesis »

You could do the following change:

Code: Select all

"description" => clienttranslate('Some players are choosing cards to give to <span style="color: #${player_color};">you</span>.')
to

Code: Select all

"description" => clienttranslate('Some players are choosing cards to give to <span style="color: #${player_color};">${direction}</span>.')
Although the player receiving cards would see its own name.
Post Reply

Return to “Developers”