Transform script only returns the else value

I am working on a simple script to just test the functionality of changing the text on a text box. The script runs but always returns nooo even when the tag value changes to a 1. What am I missing?

def transform(self, value, quality, timestamp):
red = "yeah"
grey = "nooo"
return red if value is 1 else grey

is doesn’t do what you think, use equality instead (==)


It looks like the tag is returning a boolean value,

return red if value else grey

A map transform may be a better fit for this

return red if value is True else grey

also works

Thanks. I am trying to improve my scripting. That's why I didn't use the map transform.

The gist about why is that is is an identity comparison (are these two objects exactly the same) while == is asking each object whether it's equal to the other or not.

Python takes advantage of the fact that every object can be coerced to a boolean with its if statement, as well, hence the short form @dkhayes117 noted. That is, if <expression> is sufficient; there's no need to use if <expression> == True.

(Note that 'expression' here is the fundamental computer science term, nothing to do with Ignition's "expression" language. Confused yet? :slight_smile:)