Page 1 of 2

Global variable and replay

Posted: 09 March 2017, 18:05
by docthib
Hi everyone,

I working on a card game called The Seven Seals, and I'm using a global variable to define which player took the Black Mage (role) during a hand.

When, at half of the first hand, I want to see the replay from the beginning, the Black Mage is already displayed in the playerboard like if the global was never been in the pool.

Is it normal /intended ? Or should I use database for this single field ?

Thanks for your answers ^^

Re: Global variable and replay

Posted: 12 March 2017, 22:01
by docthib
Well, i did a gif to illustrate the problem :

Image

Anyway the bug does not happen in the following hands so... maybe not a bug.

Re: Global variable and replay

Posted: 13 March 2017, 01:40
by Victoria_La
I can't say I understood the problem, the but reply is based on notifications and the fact is
UI should be 100% the reflecting the state of the game based on notifications, i.e.

a) game received full data from reload (i.e. user pressing F5), and in states that BlackMage is owned by player A
b) there was notification that said "Player B took BlackMage", and UI moved BlackMage to that player

If you never sent such notification, or UI does not react to it properly it will be a mess

Re: Global variable and replay

Posted: 13 March 2017, 14:11
by Andy_K
Not sure I can help directly, but I will say this:

The replay is based entirely on game state and notifications, and will not incorporate client side player actions. So for example if the active player does something client side, and you animated it and then send info to the server to update the backend. Then you have the server notify other players and update the action on their screens, then your replay will not work correctly because at no point was the player's client side action triggered by the server.

So basically, if your replay is incorrect, it is likely you are at some point updating the visual state of the board via client actions instead of server notifications.

Re: Global variable and replay

Posted: 14 March 2017, 10:39
by docthib
Thanks for answering both of you :)

To explain more clearly the problem :

Black mage and tokens start in the pool
- P1 takes some tokens (slide from pool to playerboard)
- P2 takes the Black mage (slide from pool to playerboard)
- P3 takes some tokens (slide from pool to playerboard)
- (...) some card played (...)

Init replay from the start (Move#1)

Black mage is displayed in P2 player board instead of pool while tokens start correctly in pool.
But you can see in notifications, that I got one which says "P2 took the Black mage"

So the initial question was : why Black Mage isn't in the pool while tokens are ?

When loading replay from #1, gamedatas (JS) has a value for Black mage player_id while it shouldn't.
Now as you both said it must be a matter of game state :

Black mage has been renamed in Saboteur
Image

So I suppose that as someone took black mage, game state 21 keep the global value... but in this way I don't know how to deal with except by managing black mage in DB

Re: Global variable and replay

Posted: 14 March 2017, 13:27
by Victoria_La
Does you reload functionality sends and places black mage in correct location? (setup function in js)
To test press F5 before and after the mage move to check
Does you notification places it in correct location?
If you JS moves it 'onlick' its not enough, it has to be moved by notifcation message as well (in case its already in right place it will be no-op)

Re: Global variable and replay

Posted: 14 March 2017, 15:30
by docthib
You can have a look at this game : http://fr.1.studio.boardgamearena.com/s ... playFrom=1

Black mage is already there as if the only thing game remember about the global var @gamestate 21 was the player_id who picked the black mage and not the inital value of 0

I think I should try to use setGameStateInitialValue() instead of setGameStateValue() in each new hand
(i use the first function in game setup only)

Strangely, when you start from replay Move#0 (URL), black mage is correctly in the pool, but the game does not display stNewHand's notifications :o

Re: Global variable and replay

Posted: 14 March 2017, 22:56
by fafa-fr
Hi,

I think there's something strange. At the beginning I thought, like Elena and Andy, that there was something wrong in your code, regarding synchronisation between game state (database), and user interface. But digging a bit more, I think it's strange that when the replay window is loading to a point in the game before the black mage ever moved to a player board, the black mage icon is still displayed in a player board. Isn't the replay feature supposed to reload the whole page ?

I don't know where the problem is, but:
docthib wrote:Or should I use database for this single field ?
docthib wrote:So I suppose that as someone took black mage, game state 21 keep the global value... but in this way I don't know how to deal with except by managing black mage in DB
I don't think this is the problem, or at least it shouldn't be. Globals ARE in database (they're just not in an independant table), so I think you should be able to use a global without problem.
(But I'm not an experienced developer, so a confirmation would be welcome)
docthib wrote:I think I should try to use setGameStateInitialValue() instead of setGameStateValue() in each new hand
I don't think it will solve the problem, it's ok to use setGameStateValue during the game.

Re: Global variable and replay

Posted: 15 March 2017, 09:16
by Andy_K
Can you post your game.php file? We may be able to see what's going wrong then (no promises though :))

Re: Global variable and replay

Posted: 15 March 2017, 10:33
by docthib
Sure !
Thanks for your help, I'm not promising extreme quality for code neither :D

https://gitlab.com/docthib/bga-sept-sce ... x.game.php

But I'm pretty sure I must have missed something in native mechanism