Notification subscription callback completely ignored in JS

Game development with Board Game Arena Studio
cervofulgure
Posts: 5
Joined: 03 January 2022, 17:52

Notification subscription callback completely ignored in JS

Post by cervofulgure »

Hello! I'm a beginner with BGA and I have a strange problem that I can't fix. The JS callback methods of my dojo.subscribe() are not called at all. However, I see the messages displayed in the game log.

In X.game.php

Code: Select all

function someMethod() {
    self::notifyAllPlayers('someEvent', 'Notification message', [...]);
}
In X.js

Code: Select all

setup: function(gamedatas) {
    // ...
    this.setupNotifications();
},

setupNotifications: function() {
    console.log('notifications subscriptions setup' ); // <-- This is printed in console log
    dojo.subscribe('someEvent', this, "notif_someEvent");
},

notif_someEvent: function(notif) {
    // This is never called :(
}
I moved the notifyPlayer/notifyAllPLayers around, in actions or state functions but it still does not work. Am I missing something? Thank you for your help!
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Notification subscription callback completely ignored in JS

Post by robinzig »

That definitely should work - I can't see anything obviously wrong with your JS code.

So I'd suggest you fall back on "stupid things" to check:

- are you sure your PHP code that sends the notification is actually executed?
- are you sure the client side receives the notification? (In Studio, below the game interface, it lists all the notifications received)
- are you sure the changes you made to your code, including the console.log, were actually uploaded to the SFTP server?

...and probably other similar things I'm not thinking of right now
cervofulgure
Posts: 5
Joined: 03 January 2022, 17:52

Re: Notification subscription callback completely ignored in JS

Post by cervofulgure »

robinzig wrote: 03 February 2022, 16:35 That definitely should work - I can't see anything obviously wrong with your JS code.

So I'd suggest you fall back on "stupid things" to check:

- are you sure your PHP code that sends the notification is actually executed?
- are you sure the client side receives the notification? (In Studio, below the game interface, it lists all the notifications received)
- are you sure the changes you made to your code, including the console.log, were actually uploaded to the SFTP server?

...and probably other similar things I'm not thinking of right now
Thank you robinzig for yout fast anwser!

- are you sure your PHP code that sends the notification is actually executed? Yes, and messages are visible in the game log
- are you sure the client side receives the notification? (In Studio, below the game interface, it lists all the notifications received) I do not see any mention of my notifications here, but there is no apparent error either
- are you sure the changes you made to your code, including the console.log, were actually uploaded to the SFTP server? Yes
cervofulgure
Posts: 5
Joined: 03 January 2022, 17:52

Re: Notification subscription callback completely ignored in JS

Post by cervofulgure »

I found this in the doc:
Notifications sent between the game start (setupNewGame) and the end of the "action" method of the first active state will never reach their destination.
I do not quite understand what ''active state" means.

Are "game" states allowed to send notifications? For instance, if some game state, let's say "newRound" notifyAllPlayers about some new visible elements on the interface, with animation, supposed to work? Theorically yes, but I was not able to see it because I can't make my synchronous notifications work :(

That brings me to another question. In case of a synchronous notification during a "game" state, how will the interface behave when it has to move to an activeplayer state? My goal is to understand how to manage some screens where no player is active but every players see the same animations (ie some new cards flipping, or tokens moved, etc) and then go to a player's turn
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Notification subscription callback completely ignored in JS

Post by robinzig »

cervofulgure wrote: 03 February 2022, 16:42 - are you sure the client side receives the notification? (In Studio, below the game interface, it lists all the notifications received) I do not see any mention of my notifications here, but there is no apparent error either
I'm not sure why you can't see this - I just checked on my game currently in development and it's in a section headed "input/output", just below the "save and restore state" buttons, which are themselves directly underneath everything you've put into the normal game interface.

But if the log messages are appearing this clearly isn't the problem - but good to know about, it can be helpful for debugging incorrect notification arguments!
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Notification subscription callback completely ignored in JS

Post by robinzig »

cervofulgure wrote: 03 February 2022, 18:09 I found this in the doc:
Notifications sent between the game start (setupNewGame) and the end of the "action" method of the first active state will never reach their destination.
I do not quite understand what ''active state" means.

Are "game" states allowed to send notifications? For instance, if some game state, let's say "newRound" notifyAllPlayers about some new visible elements on the interface, with animation, supposed to work? Theorically yes, but I was not able to see it because I can't make my synchronous notifications work :(

That brings me to another question. In case of a synchronous notification during a "game" state, how will the interface behave when it has to move to an activeplayer state? My goal is to understand how to manage some screens where no player is active but every players see the same animations (ie some new cards flipping, or tokens moved, etc) and then go to a player's turn
I'm not completely sure I understand what you're asking here. For that quote from the docs, it means exactly what it says - if you try to send notifications before any player has had the chance to become "active" (make a decision) at the start of the game, they won't happen. But that doesn't seem to be your problem here, as you confirm that the notification is happening.

To your next question though: yes, "game" states are allowed to send notifications (I did this in Deus quite a bit, for cards that can be automatically resolved with no player input required), and this works fine. Not sure I understand the followup question to this, but my own experience (still being hardly a veteran with the BGA framework - one game published and another still in the very early stages of development) is that everything behaves pretty much as expected in this case.
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Notification subscription callback completely ignored in JS

Post by robinzig »

Anyway, given what you've said, the only reason I can think of for this not to work is that some of your strings don't match. Ie. when you do this:

dojo.subscribe('someEvent', this, "notif_someEvent");

then the first argument ('someEvent') needs to match *exactly* the notification name you send from PHP, and the third, "notif_someEvent" needs to match EXACTLY your JS method name. From your code sample it appears they do, but I dunno, perhaps this wasn't copied and you made a typo in one of the files - it's easy to do! (I really wish BGA didn't have so much functionality which depending on simple "magic strings" - but well, it does.)
cervofulgure
Posts: 5
Joined: 03 January 2022, 17:52

Re: Notification subscription callback completely ignored in JS

Post by cervofulgure »

Thanks again. I'm not a BGA veteran, but I am a web developer since 2001, so checking these kind of things such as typos are second nature. I will still double check just in case.

I do have the Input / Output log, but no sign of my notifications:

Code: Select all

< updateSpectatorList
{"2362302":"cervofulgure0","2362303":"cervofulgure1"}
< updateSpectatorList
{"2362302":"cervofulgure0","2362303":"cervofulgure1"}
< chatmessage
{"player_name":"cervofulgure0","player_id":"2362302","message":"test"}
This is very frustrating
User avatar
robinzig
Posts: 459
Joined: 11 February 2021, 18:23

Re: Notification subscription callback completely ignored in JS

Post by robinzig »

cervofulgure wrote: 03 February 2022, 19:06 I do have the Input / Output log, but no sign of my notifications:

Code: Select all

< updateSpectatorList
{"2362302":"cervofulgure0","2362303":"cervofulgure1"}
< updateSpectatorList
{"2362302":"cervofulgure0","2362303":"cervofulgure1"}
< chatmessage
{"player_name":"cervofulgure0","player_id":"2362302","message":"test"}
This is very frustrating
That's weird - because that can only mean the notification isn't getting sent (or at least, not received on the client side - but there's no reason it wouldn't be received if it is sent). But you said the string you logged - "Notification message" is appearing in the game log at that point, which can't happen unless the notification is indeed received.

Maybe this is to do with that part from the docs you quoted - which is a situation I've never felt the need to experiment with. Is this notification happening in response to some player action, or in a "game" state that the game goes straight to from setup? If the latter, things definitely won't work as expected - and maybe this is what that means.
cervofulgure
Posts: 5
Joined: 03 January 2022, 17:52

Re: Notification subscription callback completely ignored in JS

Post by cervofulgure »

It goes straight to this game state from setup

setup -> newRound -> playerTurn -> etc ->

here is the pseudcode:

Code: Select all

function setup:
   do some stuff
   go to next state newRound

function stNewRound (game state):
    pick some cards and move to other location
    tell all players so we can animate cards in the ui
    self::notifyAllPlayers
    goto player turn: $this->gamestate->nextState() 

function stNextPlayer (activeplayer state):
    If first player is active player: do some stuff and notify all players
    self::notifyAllPlayers
    goto net state, etc 
** UPDATE **
Notification JS callbacks do work if they are called within a player action during the an activeplayer state.

So my question is: How the hell can we show players things moving around without being in an activeplayer state?
Post Reply

Return to “Developers”