Page 1 of 1
multipleactiveplayer & restoreServerGameState - client side
Posted: 09 February 2020, 03:41
by hersh
I'm noticing some unexpected behaviour client-side during multiactiveplayer states. I'm using this.restoreServerGameState() to cancel client-side states. However, whenever I use it the client seems to think the player is not one of the 'active' multiple players.
I notice that both onEnteringState() & last_server_state do not have 'multiactive' array populated after transitioning to a multiactiveplayer state. But if I refresh the page 'multiactive' array is populated and restoreServerGameState() works as expected. I'm not sure if its related.
am using this method incorrectly? is there an alternative?
thanks
Re: multipleactiveplayer & restoreServerGameState - client side
Posted: 09 February 2020, 17:35
by hersh
hmm I'm sure I saw a post before referencing this
thread.
While not exactly the same problem (mine is around incorrect description showing) it did get me thinking how come it works before restoreServerGameState() is called. After looking at the code it appears the function
ntf_gameStateMultipleActiveUpdate gets called to update ui for multipleactiveplayer states.
I notice the following line of code:
Code: Select all
this.gamedatas.gamestate.multiactive = _e1e.args;
but no line of code that clones that data into last_server_state. If I override the method and update last_server_state then restoreServerGameState() works as expected.
I can patch within the game I'm working on, but think it belongs in the BGA framework as last_server_state should consider this data as well.
Thoughts?
Thanks
Re: multipleactiveplayer & restoreServerGameState - client side
Posted: 10 February 2020, 10:25
by sourisdudesert
Hi,
The problem is the following: during a multipleactive player state, the players may be made inactive (and sometimes active) at anytime.
The gameStateMultipleActiveUpdate notification is here to make sure that the client know which players are actives, and which players are inactives. And this is stored in this.gamedatas.gamestate.multiactive variable.
When you do a restoreServerGameState, what you want to do is restore the initial client state for your player. HOWEVER, if some opponents has been made inactive in the meantime, you want him/her to remain inactive. It means that you don't have to update/modify this.gamedatas.gamestate.multiactive, ever, otherwise there is a risk that your player will see a player as "active" while he is considered "inactive" on server side.
So this is why restoreServerGameState do not restore "multiactive" array (and should not).
I may not have understand your initial problem, but I think this is very much the same that the problem stated in the other thread (no active players during onEnteringState).
Re: multipleactiveplayer & restoreServerGameState - client side
Posted: 10 February 2020, 15:03
by hersh
The problem I'm facing is when I use restoreServerGameState() in a multipleactive state the description reverts to gamedatas.gamestate.description instead of gamedatas.gamestate.descriptionmyturn. Also usually inside onUpdateActionButtons() we wrap the switch around this.isCurrentPlayerActive(), but it is false after calling restoreServerGameState() because multiactive is empty.
I did try the use case mentioned and I still see the other player as inactive. It looks like the same method ntf_gameStateMultipleActiveUpdate gets called when an opponent goes from active to inactive so the array gets updated. I'm not sure if there are any other side-effects. However, when I look at the updatePageTitle() and isPlayerActive() I don't see how else to make known the player to be active without updating that array.
Is there a better way to manage canceling client-side state during multipleactive states?
Thanks for the reply.