How can I set a boolean variable value to a static value when a metric is clicked on?

I want to use the “Set variable value” event on a metric with a static value as the source value. And if that isn’t possible is there another way of setting a variable value when an interactive metric is clicked?

E.g.:

  • When Metric A is clicked on, then variable X and Y are both set to true
  • When MetricB is clicked on then variable X and Y are both set to false and variable Z is set to true

“Set variable value” seems to be the only way to set a variable value, and it only accepts another variable as the source. So I have defined a variable that defaults to true and a variable that defaults to false. This works, but it is fragile. How else can I do this?

Yes, this is how I do it as well. You can create a static Boolean variable - one each for true and false and then use these as the source for the Set variable value event.

I normally create one called [b] True and one called [b] False, but that’s just my own naming convention.

Just while we’re on the topic, a related pattern I sometimes find useful is to have a pair of boolean variables that “toggle” (I often use it if I have a button that pair of buttons where one hides and the other shows to create a “toggle” interaction for showing/hiding a section, for instance.) The first static boolean is set to true (or false depending on the interaction) and the second is a variable transform boolean set to the negation of the first variable. Then your button can simply use the set variable value event to set the value of the first variable to the current value of the second, and away you go with a little toggle mechanic.

1 Like