Page 1 of 1

Update players

Posted: 17 January 2021, 21:19
by DirkDeBelg
Hello

I added custom fields to the player table and they end-up in the gamedatas.player variable.

I need to trigger an UI via an notification after that I updated some customer fields in the player table. I actually want to persist that information in the client back into the gamedatas.player object in the notification handler.

What is the best way to force a refresh of this gamesdata.player object ? In the getAllDatas() routine, it seems you don't need to specify all standard, BGA-managed fields of the player table, while they are being received on the client. When passing an array to the notification args, that is not done automatically.

Dirk

Re: Update players

Posted: 17 January 2021, 22:43
by RicardoRix
You could do this:

php notification argument, you have to rename ALL the fields to suit. The id field has to be first to make it the key of the array.

Code: Select all

 	'players' => self::getCollectionFromDB( "SELECT player_id id, player_score score, player_no,  ..additional fields... " FROM player");

JS notification:

Code: Select all

this.gamedatas.players = notif.args.players;

Re: Update players

Posted: 19 January 2021, 22:19
by DirkDeBelg
Thanks, I was indeed thinking about that way, but then I could expect future compatibility issues. What if I replace the player game and BGA would add common features to the player table. I think I'll stick to copying the whole players object into a custom client object and using that for my logic.