Skip to content

this.bga.userPreferences

User preferences

this.bga.userPreferences.get(pref_id)

Return the value of a user preference. It will return the value currently selected in the select combo box, in the top-right menu.

this.bga.userPreferences.set(pref_id, value)

Programmatically change a user preference. It will have the same effect as if the player changed the value in the select combo box, in the top-right menu.

this.bga.userPreferences.onChange

A callback you can define if you want to be notified when a user changes a user preference.

Example:

// in your Game constructor
this.bga.userPreferences.onChange = (pref_id, pref_value) => this.myGamePreferenceChanged(pref_id, pref_value);

myGamePreferenceChanged: function(pref_id, pref_value) {
  switch (pref_id) {
    case 201: 
      document.getElementsByTagName('html')[0].classList.toggle('dark-background', pref_value == 2);
      break;
  }
}

this.bga.userPreferences.toggleVisibility(pref_id, visible)

Hide or show a user preference.

Example:

myGamePreferenceChanged: function(pref_id, pref_value) {
  switch (pref_id) {
    case 101: 
      // If pref 101 is "Confirm moves" and 102 is "Countdown timer on confirm", hide the countdown user preference when move confirmation is disabled.
      this.bga.userPreferences.toggleVisibility(102, prefValue != 2);
      break;
  }
}