Page 1 of 1

Error when using self::checkAction()

Posted: 20 August 2015, 15:50
by Coin-coin le Canapin
Hi.

I have this code :

public function chooseStones($choice)
{
self::checkAction("chooseStones", true);
[…]
}

Instead of throwing an exception message like "cette action est impossible à ce moment du jeu" (french), it throws this :
Server syntax error: Warning: Invalid argument supplied for foreach() in /var/tournoi/release/tournoi-150617-1039-gs/www/game/module/table/gamestate.game.php on line 152 {"status":"0","error":"Cette action est impossible \u00e0 ce moment du jeu","expected":1,"code":900,"stack":"#0 \/var\/tournoi\/release\/tournoi-150617-1039-gs\/www\/game\/module\/table\/table.game.php(582): Gamestate->checkPlayerAction('chooseStones', true)\n#1 \/var\/tournoi\/release\/games\/fanorona\/999999-9999\/fanorona.game.php(465): Table->checkAction('chooseStones', true)\n#2 \/var\/tournoi\/release\/games\/fanorona\/999999-9999\/fanorona.action.php(70): Fanorona->chooseStones('front')\n#3 \/var\/tournoi\/release\/tournoi-150617-1039-gs\/www\/include\/webActionCore.inc.php(126): action_fanorona->chooseStones()\n#4 \/var\/tournoi\/release\/tournoi-150617-1039-gs\/www\/index.php(126): launchWebAction('fanorona', 'fanorona', 'chooseStones', false, false, NULL, true, false)\n#5 {main}"}
Any idea ?

I also don't understand something else.

The JS console tells me this :
Entering state: chooseStones
When I click on my element during this state, it triggers this :

Code: Select all

if(!this.checkAction('chooseStones')) { return ; }
and the game tells me :
This move is not authorized now
But it's during my chooseStones state, which looks like it :

Code: Select all

    5 => array(
        "name" => "chooseStones",
        "description" => clienttranslate('${actplayer} must choose which stone(s) to capture'),
        "descriptionmyturn" => clienttranslate('${you} must choose which stone(s) to capture'),
        "type" => "activeplayer",
        "possibleactions" => "chooseStones",
        "transitions" => array("captureStones" => 6)
    ),
Any idea why it keeps telling me this move is not authorized ?

Is there any way to show the current state with PHP ?

Re: Error when using self::checkAction()

Posted: 20 August 2015, 19:42
by pikiou
"possibleactions" is expected to be an array of possible actions, not a string. It could be more permisive but it's not :P

Re: Error when using self::checkAction()

Posted: 20 August 2015, 20:51
by Coin-coin le Canapin
How distracted I am… Thanks !

Re: Error when using self::checkAction()

Posted: 21 August 2015, 21:09
by Quinarbre
It is a bit strange too to label your transition with captureStones but name your possible action with something else (which, additionally, is the name of the current state).

What I don't understand (about the framework) is why possibleactions is not automatically filled with array_keys(transitions)...

Re: Error when using self::checkAction()

Posted: 21 August 2015, 21:51
by Coin-coin le Canapin
Yeah, my labels (and not only them…) are a mess.

Re: Error when using self::checkAction()

Posted: 21 August 2015, 23:37
by pikiou
What you say Quinarbre echoes to me ^^
After developing a few games I got tired of all this data and now I process my state array to add recurrent data in order to keep it simple so it looks like this:

Code: Select all

Array(
   'name' => 'yearEnd',
   'transitions' => Array('census', 'nextYear')
),
Array(
   'name' => 'census',
   'description' => clienttranslate('Some players are still deciding how many units to show'),
   'descriptionmyturn' => clienttranslate('${you} grab for the Census:'),
   'type' => 'multipleactiveplayer',
   'transitions' => Array('census', 'assignReputation', 'assignStories', 'nextYear')
),