Conditional number change

I have a listener that is set to change a number in my view model to 3 when clicked. I then want to add a condition so if that same listener is clicked while the view model number is 3 it then changes to 0.

The context is a UI element where I can click one of 3 buttons which turns specific layers on or off, and switches between those layers. So if I click the first Icon the number goes from 0 to 1, if I then click the second button the number switches from 1 to 2, and if I click the second button again the number switches back to 0.

I’ve tried a couple of hacky ways to get this to work, like swtiching the listener for another one once the first one is clicked, but it gets messy and complex.

It would be great if there was some simple logic that could be applied to the listener clicks. If the value is 3, set to 0. If it is NOT 3, set to 3.