Page 1 of 1

Game action cannot return any data ?

Posted: 09 April 2013, 14:41
by tilalilalou
Hello,

I have a state in which current player have to select 2 hexagons to play his move.
Allowed hexagons for 2nd selection depends on the 1st one. The method exists on server side, so i'm trying to implement a game action returning allowed hexagons depending on the first selection. I tried this :

self::ajaxResponse($response);

but i'm getting the following error :

Unexpected error: Game action cannot return any data

I do not want to create a state, because I would have to save somewhere the first hexagon selection, and a cancel would be hard to implement.
I also would like not to implement in client side what already exists on server side.
And for performance reasons, I think it would be a bad idea to return all allowed second moves based on every allowed first moves in state arguments.
What can I do ?

Re: Game action cannot return any data ?

Posted: 10 April 2013, 10:24
by sourisdudesert
Hello,

Indeed this is not possible to return any result from a player action: it should return nothing (action went fine) or an exception (action unsuccessful).

To return the list of possible move, you should use game state arguments, that are exactly design for this purpose. See for example:

http://en.doc.boardgamearena.com/Tutori ... owed_moves

Using game state arguments, you are sure that the need information is always available when needed, included when the player perform a page resfresh before its move.

Hope it helps,
Cheers,

Re: Game action cannot return any data ?

Posted: 10 April 2013, 10:45
by Alkazar
I see two ways of doing this : using two games states, and notifications.
Using two game states with a cancel action is not that complicated :
For example here is what's in my game.php :

Code: Select all

	function Cancel ()
	{
	self::checkAction('Cancel');
	$sql="UPDATE pieces set is_selected=null where is_selected='Y'";
	self::DbQuery($sql);
	$this->gamestate->nextState( 'Cancel');	
	}
in my .js

Code: Select all

        onUpdateActionButtons: function( stateName, args )
        {
            console.log( 'onUpdateActionButtons: '+stateName );
                      
            if( this.isCurrentPlayerActive() )
            {            
                switch( stateName )
                {
				case 'movePiece' :
				this.addActionButton('Cancel',_('Cancel'), 'onCancel');
				break;
[...]
        onCancel : function (evt)
		{
			console.log("enter on Cancel");
			if( this.checkAction( 'Cancel' ) )    // Check that this action is possible at this moment
            {            
                this.ajaxcall( "/<game>/<game>/Cancel.html", {} , this, function( result ) {} );
            }
		}
And of course it's also in my action.php :

Code: Select all

	public function Cancel()
    {
        self::setAjaxMode();     
        $result = $this->game->Cancel();
        self::ajaxResponse( );
    }
and I go back to the previous state in my states.inc.php.

Re: Game action cannot return any data ?

Posted: 10 April 2013, 15:04
by tilalilalou
Thank you for your answers,

I going to use game state arguments, and pre-process every possible combinations.

Cheers,

Tilalilalou