Page 1 of 1
store a value when the page is refreshed!
Posted: 05 May 2025, 19:11
by zim921
Hi guys!, im new here and im trying to develop my first game.
I need some help with a minor doubt. The user actions in my game is spllited in two. First one he select a token, the server response with the avaiable movements for this token. Second the user select one of this movements. The flow works if you dont refresh the page, but in that case if you refresh in the second part, the client doesnt have which tokens was selected to show the possible movements. My question is, should I store this data in the db, is just a coord (x,y) or there s a way to store in memory ? What are best practices to manage these kind of temp data?
Thanks !
edit: What are the best way to console log the server ? i tried with var dump or notify, but sometimes it fails
Re: store a value when the page is refreshed!
Posted: 05 May 2025, 19:30
by robinzig
zim921 wrote: ↑05 May 2025, 19:11
Hi guys!, im new here and im trying to develop my first game.
I need some help with a minor doubt. The user actions in my game is spllited in two. First one he select a token, the server response with the avaiable movements for this token. Second the user select one of this movements. The flow works if you dont refresh the page, but in that case if you refresh in the second part, the client doesnt have which tokens was selected to show the possible movements. My question is, should I store this data in the db, is just a coord (x,y) or there s a way to store in memory ? What are best practices to manage these kind of temp data?
Thanks !
edit: What are the best way to console log the server ? i tried with var dump or notify, but sometimes it fails
Personally I think there's no need to store anything in this case - how often will a player refresh between selecting a piece to move and then selecting where to move it to? And if this does happen and they lose their choice, is it actually a problem? (Sounds like they just need a single click to get back to where they were.)
If you do really need this to be remembered though, I wouldn't use the DB, and just use localstorage to store the information. (This still won't work if the user closes the game on one device and re-opens it on another one - but how many unimportant edge cases do you really want to cater for?)
Re: store a value when the page is refreshed!
Posted: 05 May 2025, 20:10
by zim921
mmm thanks for the answer, i know is a border case, may be the problem is my design since i split in two states. One state for select the token, which handle which tokens belong to the active user, then pass to a second state which based in the token selected calculate the available movements. But if you refresh token selected is undefined and any available movement is shown
Re: store a value when the page is refreshed!
Posted: 05 May 2025, 20:33
by robinzig
zim921 wrote: ↑05 May 2025, 20:10
mmm thanks for the answer, i know is a border case, may be the problem is my design since i split in two states. One state for select the token, which handle which tokens belong to the active user, then pass to a second state which based in the token selected calculate the available movements. But if you refresh token selected is undefined and any available movement is shown
To be clear, there's nothing wrong with this - it's a normal enough situation in many games. I just don't think you need to care about the fact that if the player happens to refresh their browser after having selected a token but before having selected where to move it to, they will lose that tiny piece of "progress". I bet the vast majority of games on BGA which have such a "multi-step" interface would behave the same way. It's both very rare that this would happen to a player, and costs almost literally no effort to the player should it actually happen.
Re: store a value when the page is refreshed!
Posted: 06 May 2025, 10:22
by KuWizard
zim921 wrote: ↑05 May 2025, 19:11
should I store this data in the db, is just a coord (x,y) or there s a way to store in memory ? What are best practices to manage these kind of temp data?
I don't see any other option rather than store it as a value somewhere in DB. I usually have a separated global_variables DB table and a class in the code for that (not that I invented this though, others use that approach too).
zim921 wrote: ↑05 May 2025, 19:11
edit: What are the best way to console log the server ? i tried with var dump or notify, but sometimes it fails
var_dump() with die() at the next line works all the time, never had any problems. Maybe it fails somewhere else, not where you put the var_dump()?
Re: store a value when the page is refreshed!
Posted: 06 May 2025, 14:02
by thoun
KuWizard wrote: ↑06 May 2025, 10:22
zim921 wrote: ↑05 May 2025, 19:11
should I store this data in the db, is just a coord (x,y) or there s a way to store in memory ? What are best practices to manage these kind of temp data?
I don't see any other option rather than store it as a value somewhere in DB. I usually have a separated global_variables DB table and a class in the code for that (not that I invented this though, others use that approach too).
Remember there is a now framework feature for storing global variables
https://en.doc.boardgamearena.com/Main_ ... se_globals
It's better to use framework functions than recreate something similar, when possible

Something like
Code: Select all
$this->globals->set('selectedCoordinates', [$x, $y]);
should do the trick.
Re: store a value when the page is refreshed!
Posted: 06 May 2025, 14:52
by KuWizard
That's amazing, I missed that one, thanks for spreading the word!