# Multistate Button Expression

**URL:** <https://forum.inductiveautomation.com/t/multistate-button-expression/93464>\
**Category:** Ignition\
**Tags:** ignition81, vision, scripting\
**Created:** [July 19, 2024, 1:49pm UTC](https://forum.inductiveautomation.com/t/multistate-button-expression/93464 "2024-07-19T13:49:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Juan\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juan\_Sanchez](https://forum.inductiveautomation.com/u/Juan_Sanchez)\
**Post date:** [July 19, 2024, 1:49pm UTC](https://forum.inductiveautomation.com/t/multistate-button-expression/93464/1 "2024-07-19T13:49:33Z")

</div>

Been trying to create an expression for a multistate button. Essentially, I want the indicator to work off two tags not just one.  
So, Hand=2, Off=1, and Auto=0 indicator value would be controlled by two boolean tags.  
Tag 1=1 and Tag 2=0 then indicatorValue=2  
Tag 1=0 and Tag 2=1 then indicatorValue=0  
Tag 1=1 and Tag 2=1 then indicatorValue=1  
Tag 1=0 and Tag 2=0 then indicatorValue=1  
Been working on it but I keep getting a syntax error using the if statement option.

---

<div class="post-metadata">

**Author:** ![Herbie](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/herbie/32/65288_2.png) [@Herbie](https://forum.inductiveautomation.com/u/Herbie)\
**Post date:** [July 19, 2024, 2:48pm UTC](https://forum.inductiveautomation.com/t/multistate-button-expression/93464/2 "2024-07-19T14:48:07Z")

</div>

So, I think you just need to properly get the Expession syntax correct. You want to evaluate the 2 boolean tags into a single integer tag that returns, 0, 1, or 2. The code should be as simple as this:

```python
if({[.]Tag1.value} && !{[.]Tag2.value}, 2, if(!{[.]Tag1.value} && {[.]Tag2.value}, 0,1))

```

---

<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:** [July 19, 2024, 3:14pm UTC](https://forum.inductiveautomation.com/t/multistate-button-expression/93464/3 "2024-07-19T15:14:17Z")

</div>

That's a frankly wacky truth table - you aren't able to enforce this logic in the PLC somewhere? That'll likely be more maintainable ultimately.

Otherwise, as @Herbie posted, you definitely _can_ do this with multiple ifs, but maintainability goes a bit out the window.

---

<div class="post-metadata">

**Author:** ![Juan\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juan\_Sanchez](https://forum.inductiveautomation.com/u/Juan_Sanchez)\
**Post date:** [July 19, 2024, 10:37pm UTC](https://forum.inductiveautomation.com/t/multistate-button-expression/93464/4 "2024-07-19T22:37:32Z")

</div>

Yes, it would be much easier through the PLC, but we are upgrading the HMI from WW to Ignition and don't want to touch PLC's, so I'm just copying what's already in place.

---

<div class="post-metadata">

**Author:** ![Juan\_Sanchez](https://avatars.discourse-cdn.com/v4/letter/j/74df32/32.png) [@Juan\_Sanchez](https://forum.inductiveautomation.com/u/Juan_Sanchez)\
**Post date:** [July 19, 2024, 10:38pm UTC](https://forum.inductiveautomation.com/t/multistate-button-expression/93464/5 "2024-07-19T22:38:17Z")

</div>

Herbie,

So, looks like my syntax was slightly off, but with your response I was able to do exactly what I needed to do. Thank you very much!
