Selection buttons integer

Hello,

I have an integer tag and I would like to be able to set every bit individually with a button in that integer.
Now for scripting I have found to use

def set_bit(value, bit):
    return value | (1<<bit)

def clear_bit(value, bit):
    return value & ~(1<<bit)
    
def getBit(value, position):
    return (value >> position) & 1
  
value = event.source.parent.DATA_Sequentie.Selectie

if	getBit(event.source.parent.DATA_Sequentie.Selectie, 0) == 0:
	value = set_bit(value,0)
	event.source.parent.DATA_Sequentie.Selectie = value
else:
	value = clear_bit(value,0)
	event.source.parent.DATA_Sequentie.Selectie = value

This works perfectly except I have to write te number 0 to the specific bit every time I make another button. I have to do this at the 3 different places the “0” bit is stated which could lead to forgetting this in the future. I would like this to come from one general place. Like a custom property for example where you have to write the bit number. Problem is I can’t get this to work.

Do you guys have any other suggestions on how I could set bits from an integer or how to get a custom property to work?

Thanks in advance!

I would move your bit shift functions to a project script if they are not already there. Then create a Template to hold your button. This will allow you to create a custom property for the template to hold the bit number reference.

Then whenever you need to add a button you can just use your template and set the properties.