Page 1 of 1

updating player boards

Posted: 07 May 2025, 03:51
by Gauben
I seem to be stuck and not able to update the player score on the board. I'm using the scoreCtrl but only when I refresh the page do the scores get updated. I'm receiving the notif with all the args but nothing after. Here are the codes I'm using.

serverside:

$newScores = $this->getCollectionFromDb("SELECT player_id, player_score FROM player", true);
$this->notify->all("scoreUpdate", "", array(
"scores" => $newScores
));
-------------------------
client side:

notif_scoreUpdate: async function(args) {
console.log("Received scoreUpdate notification with:", args);

for( var player_id in args.scores )
{
var newScore = args.scores[ player_id ];
this.scoreCtrl[ player_id ].toValue( newScore );
}
},

Re: updating player boards

Posted: 07 May 2025, 10:38
by thoun
At first sight, it seems good. Does the console.log displays what you expect in it? Do you have errors in the console?

Re: updating player boards

Posted: 07 May 2025, 12:15
by Gauben
yes actually I was able to narrow on the issue. The console log shows that all the information is sent with the notif, but the information in the args are undefined. The issue seem to be how the information is structured inside the args.

Image

Re: updating player boards

Posted: 07 May 2025, 15:16
by thoun
If you use the new notification system (bgaSetupPromiseNotifications), "notif_scoreUpdate: async function(args) {" is correct.
If you use the old way (dojo.subscribe) then you receive an objectif "notif" containing the args.
The new way ditch the useless level.

Re: updating player boards

Posted: 07 May 2025, 23:34
by Gauben
Oh thanks, that was the issue, I was sending the old way I guess, switching to notif_scoreUpdate: function(notif) fixed my problem.