database write delay ?

Game development with Board Game Arena Studio
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

database write delay ?

Post by tchobello »

hello

I'm struggling with a value just updated in DB.
I need this value as an argument in the State CombatChoices.
PHP

Code: Select all

$sql = "UPDATE token SET token_specialpower_counter='-10' WHERE token_id='".$part_token['id']."
self::DbQuery( $sql );
$twoHandedSword ++;
																			
if( $twoHandedSword > 0 ){
	 $this->gamestate->nextState( 'combatchoices' );

    function argCombatChoices()    {
        $token = self::getObjectListFromDb( "SELECT token_id id, token_type type FROM token WHERE token_specialpower_counter ='-10' ");
	$nb_tokens = count($token);
	$token_type = $token[0]['type'];
        return array(
            'nb_tokens' => $nb_tokens,
            'token_type' => $token_type
			);
JS returns 'Cannot read property 'token_type' of null'
and it's working perfectly when hitting F5...

Can someone explain to me what is happening here ?
User avatar
Tisaac
Posts: 2736
Joined: 26 August 2014, 21:28

Re: database write delay ?

Post by Tisaac »

This is not an issue with the db but more like an issue with the js onEnteringState (that is solved when refreshing since it's the setup fonction that handle it).
Can you post the corresponding states.php and .js ?
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: database write delay ?

Post by tchobello »

Thanks for answering

STATES

Code: Select all

    4141 => array(
        "name" => "combatChoices",
        "description" => clienttranslate('${actplayer} must choose a Combat option'),
        "descriptionmyturn" => clienttranslate('${you} must choose a Combat option'),
        "type" => "activeplayer",
        "args" => "argCombatChoices",
        "possibleactions" => array( "chooseCombatOption" ),
        "transitions" => array( "chooseCombatOption" => 48 )
PHP

Code: Select all

    function argCombatChoices()
    {
        $token = self::getObjectListFromDb( "SELECT token_id id, token_type type FROM token WHERE token_specialpower_counter ='-10' ");
		$nb_tokens = count($token);
		$token_type = $token[0]['type'];
        return array(
            'nb_tokens' => $nb_tokens,
            'token_type' => $token_type
	    );
	}
JS ONUPDATEACTIONBUTTONS

Code: Select all

         case 'combatChoices':
			if( args.token_type == 'twohandedsword' ){
				for( var i=0;i<=args.nb_tokens;i++ ){
					this.addActionButton( 'combatchoice_'+args.token_type+'_'+i, dojo.string.substitute( _("Use ${nb} Two-Handed Sword(s)"), {nb: _(i) } ), 'onCombatChoice' );
				}
		        }
		        break;
Last edited by tchobello on 30 May 2020, 20:09, edited 1 time in total.
User avatar
Benoit314
Posts: 82
Joined: 02 April 2020, 22:12

Re: database write delay ?

Post by Benoit314 »

Did you try with args.args.token_type?
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: database write delay ?

Post by tchobello »

Benoit314 wrote: 30 May 2020, 19:31 Did you try with args.args.token_type?
yep.
does not work...
User avatar
Benoit314
Posts: 82
Joined: 02 April 2020, 22:12

Re: database write delay ?

Post by Benoit314 »

If you use console.log(), what values are returned in args?
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: database write delay ?

Post by tchobello »

Benoit314 wrote: 30 May 2020, 20:55 If you use console.log(), what values are returned in args?
null at first
twohandedsword (as expected) after F5
User avatar
Lymon Flowers
Posts: 195
Joined: 01 April 2020, 21:14

Re: database write delay ?

Post by Lymon Flowers »

Code: Select all

				for( var i=0;i<=args.nb_tokens;i++ ){
Isn't the <= problematic? You should probably use "i<args.nb_tokens" instead.
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: database write delay ?

Post by DrKarotte »

Maybe the args are not available in the updateActionButtons, I think I had some trouble with that.
I stored the info I need during the enteringState in a global variable.

Apart from that it is always args.args.xyz, unless you define var args=args.args;
User avatar
tchobello
Posts: 693
Joined: 18 March 2012, 13:19

Re: database write delay ?

Post by tchobello »

DrKarotte wrote: 31 May 2020, 12:22 Maybe the args are not available in the updateActionButtons, I think I had some trouble with that.
I stored the info I need during the enteringState in a global variable.

Apart from that it is always args.args.xyz, unless you define var args=args.args;
I need the arguments only for displaying buttons. Therefore, I only use the OnUpdateActionsButton part.
I think it's args.args.xyz in OnEnteringState and args.xyz in OnUpdateActionsButton...
Post Reply

Return to “Developers”