React to change of preference

Game development with Board Game Arena Studio
Post Reply
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

React to change of preference

Post 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 !
User avatar
DrKarotte
Posts: 279
Joined: 22 September 2015, 23:42

Re: React to change of preference

Post 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.
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: React to change of preference

Post by Draasill »

Hello,

the game tarot (frenchtarot) has it too.
User avatar
Tisaac
Posts: 2743
Joined: 26 August 2014, 21:28

Re: React to change of preference

Post 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 !
User avatar
Draasill
Posts: 197
Joined: 26 April 2020, 00:00

Re: React to change of preference

Post by Draasill »

Yes I was really surprised too, there are some legacy parts in BGA, like this one ^^
Post Reply

Return to “Developers”