Toggle Boolean when number is increased

Hi together,

what I am trying to achieve is a boolean that switches every time a value is increased by 1. Example: I have a button. The number the button is pressed is stored in a list and every time it is pressed increased by one. How can a boolean state be switched every time the button is pressed and thus the number increased by.

Is there an easy solution? Thanks in advance.

1 Like

I prefer the solution from Ivelin; but if you want to avoid Python this could be another option.

Thanks for your solutions, however I think I explained it wrong. The button an counter stuff I got already. Now I want to have a boolean switching every time the number is increased.

You could use the modulus 2 of the output.


2 Likes

You can add another output to my python script that calculates:

b = a%2

2 Likes

Hi @ivelin.peychev,

One thing to bear in mind is that sticky is a global dictionary, so if you have two components both using ‘a’ as the key they will share the value and interact - which may or may not be what you want.

If you don’t want it, an easy way to avoid it is to use the component guid as the key, like so:

g = ghenv.Component.InstanceGuid

if g in sc.sticky.keys():
    a = sc.sticky[g]
else:
    …

Regards
Jeremy

1 Like

Yes, good point @jeremy5, thanks.