Refreshing Player Boards (Resolved)

Game development with Board Game Arena Studio
Post Reply
Gauben
Posts: 11
Joined: 23 February 2025, 20:45

Refreshing Player Boards (Resolved)

Post 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.
Last edited by Gauben on 14 April 2025, 03:06, edited 1 time in total.
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Refreshing Player Boards

Post 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.
Gauben
Posts: 11
Joined: 23 February 2025, 20:45

Re: Refreshing Player Boards

Post 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!
Gauben
Posts: 11
Joined: 23 February 2025, 20:45

Re: Refreshing Player Boards

Post 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);
}
Gauben
Posts: 11
Joined: 23 February 2025, 20:45

Re: Refreshing Player Boards (Resolved)

Post by Gauben »

I was able to fetch the information with getObjectListFromDB()
Thanks!
User avatar
RicardoRix
Posts: 2548
Joined: 29 April 2012, 23:43

Re: Refreshing Player Boards (Resolved)

Post 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
Gauben
Posts: 11
Joined: 23 February 2025, 20:45

Re: Refreshing Player Boards (Resolved)

Post 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.
Post Reply

Return to “Developers”