# MultiState Indicator Scripting

**URL:** <https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [August 1, 2023, 12:11am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175 "2023-08-01T00:11:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shirshak\_Chhetri](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Shirshak\_Chhetri](https://forum.inductiveautomation.com/u/Shirshak_Chhetri)\
**Post date:** [August 1, 2023, 12:11am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/1 "2023-08-01T00:11:10Z")

</div>

```auto
if event.propertyName == 'Tag2' and event.newValue > event.oldValue:
	event.source.state = 0
elif event.propertyName == 'Tag1' and event.newValue > event.oldValue:
	event.source.state = 1

```

This is the script I'm using to trigger two states based on which one changes. If I add a third state which is "empty" and only supposed to come on when Tag1 and Tag2 are 0. How do I add the third tag in there.

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 1, 2023, 12:20am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/2 "2023-08-01T00:20:28Z")

</div>

```auto
if event.propertyName == "Tag2":
	#If new value is 0 and other tag value is 0, mark as empty state
	if not event.newValue and not event.source.Tag1:
		event.source.state = 2
	
	#Mark as state 0 if new value is larger than old
	elif event.newValue > event.oldValue:
		event.source.state = 0

elif event.propertyName == "Tag1":
	#If new value is 0 and other tag value is 0, mark as empty state
	if not event.newValue and not event.source.Tag2:
		event.source.state = 2
	
	#Mark as state 1 if new value is greater than old
	elif event.newValue > event.oldValue:
		event.source.state = 1

```

---

<div class="post-metadata">

**Author:** ![Shirshak\_Chhetri](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Shirshak\_Chhetri](https://forum.inductiveautomation.com/u/Shirshak_Chhetri)\
**Post date:** [August 1, 2023, 12:38am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/3 "2023-08-01T00:38:41Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/7/e/7e4980c1c8d44a488432fb71b0993390c8d73e5b.png)  
Tag 1 and Tag 2 correspond to state 1(fail) and 2(pass) respectively. But I have a tag 3 which in itself turns 1 when tag 1 and 2 are 0. So I can now use tag 3 to dictate the state 3(hide), or use the condition when tag 1 and 2 equals 0, event.source = 2.

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/8/d86c99d1ed1ae48bebeb7dfe2959794248838452.png)

---

<div class="post-metadata">

**Author:** ![ryan.white](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/ryan.white/32/73193_2.png) [@ryan.white](https://forum.inductiveautomation.com/u/ryan.white)\
**Post date:** [August 1, 2023, 12:56am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/4 "2023-08-01T00:56:00Z")

</div>

The code I provided in my previous reply would check for the tag firing the event and other tag (tag 1 and tag2) to both be zero and set the state to 2 if they were both 0. Otherwise it would follow the normal logic you had originally.

If you want it to look at the value of Tag 3 instead, add the following to the end of your original script:

```auto
elif event.propertyName == "Tag3" and event.newValue:
	event.source.state = 2

```

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 1, 2023, 1:03am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/5 "2023-08-01T01:03:24Z")

</div>

Consider ditching all scripting and adding an additional custom property using the `binEnc` expression function:  
[https://docs.inductiveautomation.com/display/DOC81/binEnc](https://docs.inductiveautomation.com/display/DOC81/binEnc)

---

<div class="post-metadata">

**Author:** ![Shirshak\_Chhetri](https://avatars.discourse-cdn.com/v4/letter/s/c89c15/32.png) [@Shirshak\_Chhetri](https://forum.inductiveautomation.com/u/Shirshak_Chhetri)\
**Post date:** [August 1, 2023, 1:04am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/6 "2023-08-01T01:04:33Z")

</div>

I tried your previous code and the added the last code to my original code as well. But it does not toggle to the third state. Only displays the pass and fail indicator.

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 1, 2023, 9:49am UTC](https://forum.inductiveautomation.com/t/multistate-indicator-scripting/77175/8 "2023-08-01T09:49:03Z")

</div>

> [@paul-griffith](#):
>
> Consider ditching all scripting

I don't think _any_ other option should be considered other than using an expression here

`binEnc({Tag1}, {Tag2}, {tag3} ) `  
Will get you a binary encoded integer from 0 to 7 where Tag1 on = 1, Tag2 on = 2, tag3 on = 4
