IF Statement trouble

The following IF statement is not working. Please advise

def transform(self, value, quality, timestamp):
	# read op10_count to determine when the count changed
	myCountValue = system.tag.readBlocking(["[default]X5-LH/OP10_Count"])[0].value
	myLastCount = {self.custom.lastCount}
	myValue = system.tag.readBlocking(["[default]X5-LH/OP10_CycleTime"])[0].value
	if myCountValue != myLastCount:
		self.getSibling("SCT02").props.text = self.custom.lastCount
		self.getSibling("SCT03").props.text = myCountValue
		self.getSibling("SCT04").props.text = system.date.getSecond(timestamp)
		self.custom.lastCount = myCountValue
		#self.getSibling("SCT04").props.text = system.date.getSecond(timestamp)
		#self.getSibling("SCT10").props.text = self.getSibling("SCT09").props.text
		#self.getSibling("SCT09").props.text = self.getSibling("SCT08").props.text
		#self.getSibling("SCT08").props.text = self.getSibling("SCT07").props.text
		#self.getSibling("SCT07").props.text = self.getSibling("SCT06").props.text
		#self.getSibling("SCT06").props.text = self.getSibling("SCT05").props.text
		#self.getSibling("SCT05").props.text = self.getSibling("SCT04").props.text
		#self.getSibling("SCT04").props.text = self.getSibling("SCT03").props.text
		#self.getSibling("SCT03").props.text = self.getSibling("SCT02").props.text
		#self.getSibling("SCT02").props.text = self.getSibling("SCT01").props.text
	return myValue

Here's some food for thought:

>>> foo = 0
>>> bar = {0}
>>> foo == bar
>>> type(foo)
<class 'int'>
>>> type(bar)
<class 'set'>

1 Like

It looks like your variable myCountValue is a single value from the [0] index of the tag.readBlocking result. I'm assuming a float or int. Whereas your myLastCount value is being created as a set.

Your variables you're comparing have to be of the same type basically. Each data type in Python has an "__ ne __" method in them that is used to evaluate != statements. But if the things compared aren't the same type then it doesn't know what to do with it.

Thank you. Is there a way to read a custom property into a float or int?
I kept getting errors when I tried to say;
myLastCount = self.custom.lastCount

Should it be;
myLastCount = {self.custom.lastCount}[0].value
or similar?


What errors did you get?

Probably not. What it {self.custom.lastCount} exactly, and what error do you get ?

In simpler terms: why do you keep adding curly braces to things? You need those in Ignition's expression language, because they're a hint to the parser to look up a dynamic reference.

In any scripting context, you're just writing regular Python code, where curly braces are used for dict or set literals; looking up things like tag paths and property references involves regular function calls and attribute access.

1 Like

Thanks for the feedback. I realize now what my mistake was and have everything working as expected.
I was using the dict set in a different piece of code and it carried over subconsciously. I'm also dealing with C++, T-SQL, GraphQL, JavaScript and a few others on many projects. Anyway, many thanks.