Page 1 of 1
React to change of preference
Posted: 30 May 2020, 00:51
by Tisaac
Hi!
I've added a preference to my game following instructions here :
http://en.doc.boardgamearena.com/Game_o ... ns.inc.php
However, the instructions only explained how to get the value, which is fine is the change needs a reload.
In my case, I would like to do without the reload, but then how can I know that a preference has been changed ? I tried looking at the console but didn't see anything logged.
Thanks !
Re: React to change of preference
Posted: 30 May 2020, 09:06
by DrKarotte
The best here is to check the code of a game which has a preference added, e.g. Briscola, where you can change the deck style.
At the JS setup game read the value as written in the documentation and store it in a global variable, which you set at a standard/start value. If the value read is the same as the value of the global, the user has the standard setting, so you don't do anything. If not you change the interface according to his setting (whatever you want to do).
You will also need to write an event listener to the preference change, so that you can perform this action directly when a player changes the setting.
The Briscola code also shows how to trigger the setting change with a button.
Re: React to change of preference
Posted: 30 May 2020, 11:09
by Draasill
Hello,
the game tarot (frenchtarot) has it too.
Re: React to change of preference
Posted: 02 June 2020, 10:34
by Tisaac
DrKarotte wrote: ↑30 May 2020, 09:06
You will also need to write an event listener to the preference change, so that you can perform this action directly when a player changes the setting.
This was precisely my question ! I've looked up Briscola and found out that you actually have to hardcode it by adding an event listener to the select !! (and then read the value again from the selected option instead of using this.prefs)
I don't get why the BGA framework don't have a simple onUpdatePreference hook that wrap all this and changes the variable this.prefs ??
Anyway, it's working so thanks for pointing out the game !
Re: React to change of preference
Posted: 02 June 2020, 10:52
by Draasill
Yes I was really surprised too, there are some legacy parts in BGA, like this one ^^