Syntax error on text expression

Hello! I am trying to get a text to change what it says based on if 2 tags are true or false. For example, if the RDY (ready) tag is on and the RNG (running) tag is on, the text should say ‘RUNNING’. I have a tag path property on the popup window (in vision) and want this to work indirectly so that the expression on the text will find the RDY and RNG tag of any tag path given. I have tried a few different chunks of code and I can’t get around some errors. If anyone has any advice, it would be greatly appreciated. Here are the two pieces of code I have been experimenting with:

ready = system.tag.writeToTag((event.source.parent.TagPath)+"/RDY", value)
running = system.tag.writeToTag((event.source.parent.TagPath)+"/RNG", value)
if (ready=1 && running=1, "RUNNING",
if (ready=1 && running=0, "READY",
if (ready=0, "NOT READY")))

and…

if ({[default]Root Container.TagPath/RDY}=1 && {[default]Root Container.TagPath/RNG}=1, "RUNNING",
if ({[default]Root Container.TagPath/RDY}=1 && {[default]Root Container.TagPath/RNG}=0, "READY",
if ({[default]Root Container.TagPath/RDY}=0, "NOT READY")))

Try this for the expression

if ({default]Root Container.TagPath/RDY} && {[default]Root Container.TagPath/RNG}, "RUNNING",
if ({[default]Root Container.TagPath/RDY} && !{[default]Root Container.TagPath/RNG}, "READY",
"NOT READY"))

Your expression doesn’t work because you don’t have a default value (else) for the last if statement you had, but you don’t need the 3rd if

1 Like

Thanks for this! When I try this I get an error that says “Invalid tag path: ‘[default]Root Container.TagPath/RDY’. Token PATH_SEPARATOR found after property name.”

Delete out the tag paths from the expression, then re-insert them by using the tag browser on the right side of the expression window.

It looks like you are mixing up the scripting language and the expression language.

EDIT:
Oh I see, you want indirect tag paths. Check out the tag expression tag - Ignition User Manual 8.1 - Ignition Documentation (inductiveautomation.com)

1 Like

You can also create custom properties bound to an indirect address. Then use those properties in your expression.

2 Likes
if (tag("sometagpath"+"/RDY")=1 && tag("sometagpath"+"/RNG")=1, "RUNNING",
if (tag("sometagpath"+"/RDY")=1 && tag("sometagpath"+"/RNG")=0, "READY",
if (tag("sometagpath"+"/RNG")=0, "NOT READY")))
1 Like

This seems to solve some of my problems but when I use the code below, I get this error:
“Syntax Error on Token: ‘COMMA’ (Line 1 , Char 86)”
I’ve tried a few different variations and can’t get them to work. Do you know what I am doing wrong? Thank you!!

if (tag("Root Container.TagPath"+"/RDY")=1 && tag("Root Container.TagPath"+"/RNG")=1, "RUNNING",
if (tag("Root Container.TagPath"+"/RDY")=1 && tag("Root Container.TagPath"+"/RNG")=0, "READY",
if (tag("Root Container.TagPath"+"/RDY")=0, "NOT READY")))

hm nvm idk what you are trying here xd

Yes, thanks I’ve fixed that now. Unfortunately, I am still getting the COMMA error.

you are missing a second value here if the if is false somehting like this? if(tag("Root Container.TagPath"+"/RDY")=0, "NOT READY","NOT READY?")

this does not give me parsing errors:
if (tag("Root Container.TagPath"+"/RDY")=1 && tag("Root Container.TagPath"+"/RNG")=1, "RUNNING", if(tag("Root Container.TagPath"+"/RDY")=1 && tag("Root Container.TagPath"+"/RNG")=0, "READY",if(tag("Root Container.TagPath"+"/RDY")=0, "NOT READY","NOT READY?")))

1 Like

I’ve discovered a new way to look at these situations with case instead of nested ifs, thanks to @mcgheeiv.

case(True
    , tag("Root Container.TagPath"+"/RDY") && tag("Root Container.TagPath"+"/RNG"), "RUNNING"
    , tag("Root Container.TagPath"+"/RDY") && !tag("Root Container.TagPath"+"/RNG"), "READY"
    , !tag("Root Container.TagPath"+"/RDY"), "NOT READY"
    , "NOT READY")
2 Likes