Changing rectangle color based on multiple tag value

I am having 4 boolean tags. when either of the tag is ‘1’ i need to change the color of the rectangle .
for example:
when tag 1 is true, the rectangle color should be red
when tag 2 is true, the rectangle color should be green
when tag 3 is true, the rectangle color should be yellow
when tag 4 is true, the rectangle color should be blue

how an i do this using scripting?

Consider using the style customizer, instead.

After rereading your post, make a custom property with a binEnc function to generate the value. The style customizer should use that property as the driving value.

Jordan pointed out what seems to be the ideal way to do something like this but, out of curiosity, if you really want to do this via scripting, it would look something like this:

Tag1 = 
Tag2 = 
Tag3 = 
if tag 1 == True:
	event.source.fillPaint = system.gui.color(255,0,0) #Red

if Tag2 == True:
	event.source.fillPaint = system.gui.color(0,255,0) #Green

if Tag3 == True:
	event.source.fillPaint = system.gui.color(255,255,0) #Yellow

if Tag4 == True:
	event.source.fillPaint = system.gui.color(0,0,255)  #Blue

event.source.fillPaint” is just a reference to the component you’re changing the color of, then system.gui.color returns the color object you want.
But, you still need to worry about how to set up your trigger, otherwise your script would not execute when you want it to.
If i was’t able to use styles for some reason, i would still use custom properties with the tag values and use the property change method to trigger only when one of the tag changes.

can u be little more brief regarding this?

More brief?
“use binEnc with Style Customiser” :slight_smile:

However, to elaborate instead, Jordan’s suggesting to bind a new custom property to the binEnc expression function e.g. binEnc({tag1}, {tag2}, {tag3}, {tag4}) and then use that property as the driving property in a Style Customiser applied to your component. Then you can set the properties you wish to change based on the combination of tags. binEnc will encode your 4 tags into a single binary number. If tag1 and tag2 are on, then it returns 3 (0011 binary converted to decimal = 3).

If your tags are mutually exclusive, then you could also use binEnum which will then just return the index position of the first “true” tag.

1 Like