Page 1 of 1

currentPlayerId inside of args

Posted: 30 May 2020, 13:58
by MikeIsHere
So in the middle of a game I changed my args for dealer name to be

Code: Select all

function argDealerName() {
    $players = self::loadPlayersBasicInfos();
    $dealer_id = self::getDealerId();
    if ($dealer_id == 0) {
        throw feException("crib player not set");
    }

    $dealerName = ($dealer_id == self::getCurrentPlayerId()) ? self::_("Your") : $players[$dealer_id]['player_name'];
    return array (
        'dealer' => $dealerName
    );
}
So in a multipleactiveplayer if you were the active dealer then it would say Your crib and if not something like "Mike's Crib"
getDealerId just gets a gameStateValue or 0 if not set for some reason

The only reference to argDealerName is in state 10 which is about 3 states into the game

Code: Select all

10 => array(
        "name" => "giveToCrib",
        "description" => clienttranslate('Some players must choose 2 cards to give to ${dealer} crib'),
        "descriptionmyturn" => clienttranslate('${you} must choose 2 cards to give to ${dealer} crib'),
        "type" => "multipleactiveplayer",
        "action" => "stGiveCards",
        "args" => "argDealerName",
        "possibleactions" => array( "giveCards"),
        "transitions" => array("giveCards"=>15)
    ),
Everything worked find until this morning

This morning when I went to start a new game I get this error message on Express Start and it doesn't even make it to the splash screen

Unexpected error: Propagating error from GS 1 (method: createGame): Fatal error during cribbagemike setup: Not logged

Man that was hard to debug. I had to rolllback a change set and apply each file separately then once in the game file I did line by line

But anyways, what I have come to find out is appearently argsDealerName is getting called very early on, even before referenced it appears and :getCurrentPlayerId() is throwing the error

I can't even do
$id = self::getCurrentPlayerId();
without throwing an error

So my questions are why does args get called on game setup and if I can't do this what is the proper way in a multiaction step see if the current client is also the dealer in a game variable

Re: currentPlayerId inside of args

Posted: 30 May 2020, 16:35
by Benoit314
I think you should check a bit more about state args functions in the doc. Check this page for your error: http://en.doc.boardgamearena.com/Troubl ... Not_logged
I think a general rule is args function can be called anytime, when the framework needs it, but it doesn't mean it is called when you expect it to be. Avoid throwing errors in args functions, if it is called, it just expects some values.

So you cannot use getCurrentPlayerId in args function, you must use getActivePlayerId, but since you are in a multiactiveplayer state, cannot use this also...

In the doc, you can use private info (http://en.doc.boardgamearena.com/Your_g ... c.php#args) but it says it uses a lot of resources in a multiactivestate. I suppose each time someone make a move it updates it again.
My way of doing it would be to send a notification when the dealer is changed (I don't know your game, if it is frequent or not) and update the dealer Id in my js variable. Then when you enter your 'giveToCrib' state, update the description in js with the correct value.

Last comment, you can use getActivePlayerName() or getPlayerNameById($player_id).

EDIT: Just saw it is a multipleactiveplayer state, so I updated my answer

Re: currentPlayerId inside of args

Posted: 31 May 2020, 20:32
by MikeIsHere
Thank you.
I can not find the method to update the status bar itself

onUpdateActionButtons allow you to attach a button to the status bar, but how would I update the description of a step client side?
I guess I can target the element directly however, would that create a flash as the value is being updated ?

Re: currentPlayerId inside of args

Posted: 31 May 2020, 21:59
by fafa-fr
MikeIsHere wrote: 31 May 2020, 20:32 I can not find the method to update the status bar itself
onUpdateActionButtons allow you to attach a button to the status bar, but how would I update the description of a step client side?
Hi,
This is not documented (I don't know why, admins, can we use this?), but there is a way:

Code: Select all

this.gamedatas.gamestate.descriptionmyturn = _( "You may move a worker" );
this.updatePageTitle();
By the way, about
MikeIsHere wrote: then it would say Your crib and if not something like "Mike's Crib"

Code: Select all

clienttranslate('Some players must choose 2 cards to give to ${dealer} crib')
I don't know if you still intend to do something like this, but you shouldn't do this, I mean use the same string to translate if it has an arg that can sometimes be a noun and sometimes a pronoun. In some languages, the translation won't be the same.

Re: currentPlayerId inside of args

Posted: 31 May 2020, 22:11
by MikeIsHere
Thank you I will try that
The two options would be

Some players must choose 2 cards to give to Mike's crib (opp name if you are giving cards to them)
or
Some players must choose 2 cards to give to Your crib (Your if you are giving cards to you)

because what it says now is
You must choose 2 cards to give to Mike's crib ( When Mike = You ) and it just looks weird in English

Re: currentPlayerId inside of args

Posted: 01 June 2020, 04:01
by VanHlebar
Also if you want to change the status bar you might look at clientStates. You can change the client Sid state with setClientState

Here is an example from my game El Grande:

Code: Select all

                    this.setClientState("client_useActionStack1Card", {
                        descriptionmyturn : _("${you} may move up to ${player_cabs_to_move} of your Caballeros."),
                        args : this.clientStateArgs
                    });