Syntax error with python expression

Hi, I'm new to python and had a question about an error that I am getting
I have two memory tags that are integer data type and they evaluate to either 1 or 0. I want a third component to set its visibility to true if both tags are 1, else false.

I have this expression worked out but am getting a syntax error message that I can't figure out.

expression:
if (tag({[default]Password Bit}) == 1 and tag({[default]Username_Bit}) == 1, 1, 0)

error message:
Syntax Error on Token: 'EQUAL' (Line 1 , Char 35)

I don't know why that equals sign would be an issue?

Thanks

Don't use double equals in an expression. In many programming languages, double equals are needed to differentiate comparison from variable assignment, but expression language doesn't work that way.

Edit: I also noticed that and is being used instead of &&, Ignition's expression language is not python, so there are some differences in syntax.

2 Likes

Also, you don’t need to (and probably shouldn’t) use the 'tag', expression. That expression is used to resolve a dynamic tag name to its value at runtime. Because you already know your tag names and they are static, your expression should simply be:

{[default]Password Bit} && {[default]Username_Bit}

There are some other caveats to using the Tag expression function especially in a Vision application. Generally, stay away from it.

Also, as @justinedwards.jle noted, the expression language is not Python. It is its own language written by IA. The two languages can not be mixed (except for when they happen to share syntax).

5 Likes

Another option is to use tag bindings on custom properties and use the custom properties in the expression.

Laslty, if statements that return [true, false] or [1, 0] values are never needed because the condition for the if statement can always speak for itself in the expression.

3 Likes

Thank you guys that helped alot