Page 1 of 1
Refreshing Player Boards (Resolved)
Posted: 13 April 2025, 23:01
by Gauben
I'm new and trying to figure out how to refresh the playerboard information in my game to show the new quantity of an item. Seems like when changing states, there is no page update going on and I need to refresh the browser page to see the change in the playerboard. I feel like it is a simple solution but cannot find it.
Re: Refreshing Player Boards
Posted: 14 April 2025, 00:56
by RicardoRix
Passing data from server to client:
it's usually done with BGA framework notifications.
But you can also do this with arguments of state changes.
You then need to update the UI on the client accordingly.
Re: Refreshing Player Boards
Posted: 14 April 2025, 01:32
by Gauben
Thanks, I'm tracking my notification step by step to see where the issue occurs, it seems like the notification is sent and received, but the information in it is undefined. Gonna come back for help with more information if I can't figure it out alone. Thanks again!
Re: Refreshing Player Boards
Posted: 14 April 2025, 02:21
by Gauben
Ok so the issue is that I cant find a way to send the updated quantity associated with the ingredient in the notification, no matter how I try to fetch it.
Here is the code
if ($ingr && isset(self::INGREDIENTS[$ingr])) {
$dbColumn = self::INGREDIENTS[$ingr]['db_column'];
$sql = "UPDATE player SET $dbColumn = $dbColumn + 1 WHERE player_id = $playerId";
self::DbQuery($sql);
$this->notifyPlayer(
$playerId,
self::INGREDIENTS[$ingr]['notification'],
clienttranslate('You gathered one ${ingredient}.'),
[
'ingredient' => self::INGREDIENTS[$ingr]['translation_key'],
'player_id' => $playerId,
);
$this->gamestate->nextState("actGatherIngr");
} else {
error_log("Invalid ingredient key in actGatherIngr: " . $ingr);
}
Re: Refreshing Player Boards (Resolved)
Posted: 14 April 2025, 03:07
by Gauben
I was able to fetch the information with getObjectListFromDB()
Thanks!
Re: Refreshing Player Boards (Resolved)
Posted: 14 April 2025, 09:36
by RicardoRix
so that is just the server side code.
The 2nd argument of notifyPlayer() will be the function handler that gets called client side.
'playIngredient ' for example.
You now need a notification handler on the JS client side.
notif_playIngredient: function( notif )
{
console.write('notif: ' + notif.args.player_id);
// handle the data, move stuff around, update player panels.
}
and you register this function as well in setupNotifications() (unless done automatically).
https://en.doc.boardgamearena.com/Game_ ... ifications
Re: Refreshing Player Boards (Resolved)
Posted: 14 April 2025, 12:12
by Gauben
Yes I had all of those, everything else was working, my client was receiving the notification but since the updated quantity was missing from the server side notification, the client side handler could not refresh my quantity from the player board. Before that, my issue was also that I was not sending the player ID so the board of the current player could not refresh at all. Now everything works.