A simple If/Else using a Formula Converter

It may seem obvious in retrospect, but It took me some time to figure this out, since as of yet, there are no built in conditionals that we can use in data binding.

As an example I was trying to toggle a dynamic rotation value being passed from my view model to a rotation property of a layer based on a condition (whether the pointer is over the hitbox or not)


so the simple solution is this:

1. Create a Number Input in the view model and call it condition_boolean.


2. Then add an additional instruction to the pointer enter/exit listeners in the State Machine, to do a View Model Change and have it set the condition_boolean to 1 for true and 0 for false.

  1. Then add a Formula Converter and write this formula

{{view_model/condition_boolean}}*{Input}

(input being the original calculated value) this way if the condition is true it multiplied input by 1 and returned the value and if it was false then it multiplied by 0 and returned 0.

PS this is like the old After Effects expressions trick to toggle opacity with a checkbox - you multiply the opacity by checkbox value (0 or 1)