# IF Statement trouble

**URL:** <https://forum.inductiveautomation.com/t/if-statement-trouble/72681>\
**Category:** Ignition\
**Created:** [April 20, 2023, 1:33am UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681 "2023-04-20T01:33:31Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Kim\_Burndred](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@Kim\_Burndred](https://forum.inductiveautomation.com/u/Kim_Burndred)\
**Post date:** [April 20, 2023, 1:33am UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/1 "2023-04-20T01:33:31Z")

</div>

The following IF statement is not working. Please advise

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/2/f/2fdfe001f8f0905b043ff792ba12e7133f6317a9.png)

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 20, 2023, 2:15am UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/2 "2023-04-20T02:15:21Z")

</div>

Here's some food for thought:

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

```

---

<div class="post-metadata">

**Author:** ![Jordan\_Mungo](https://avatars.discourse-cdn.com/v4/letter/j/439d5e/32.png) [@Jordan\_Mungo](https://forum.inductiveautomation.com/u/Jordan_Mungo)\
**Post date:** [April 20, 2023, 2:59am UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/3 "2023-04-20T02:59:05Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kim\_Burndred](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@Kim\_Burndred](https://forum.inductiveautomation.com/u/Kim_Burndred)\
**Post date:** [April 20, 2023, 1:59pm UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/4 "2023-04-20T13:59:01Z")

</div>

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?

Thanks

---

<div class="post-metadata">

**Author:** ![Kevin.Herron](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/kevin.herron/32/7259_2.png) [@Kevin.Herron](https://forum.inductiveautomation.com/u/Kevin.Herron)\
**Post date:** [April 20, 2023, 2:00pm UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/5 "2023-04-20T14:00:48Z")

</div>

> [@Kim\_Burndred](#):
>
> I kept getting errors when I tried to say;  
> myLastCount = self.custom.lastCount

What errors did you get?

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [April 20, 2023, 2:01pm UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/6 "2023-04-20T14:01:20Z")

</div>

> [@Kim\_Burndred](#):
>
> Should it be;  
> myLastCount = {self.custom.lastCount}[0].value  
> or similar?

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

---

<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:** [April 20, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/7 "2023-04-20T14:42:57Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Kim\_Burndred](https://avatars.discourse-cdn.com/v4/letter/k/90ced4/32.png) [@Kim\_Burndred](https://forum.inductiveautomation.com/u/Kim_Burndred)\
**Post date:** [April 21, 2023, 12:03am UTC](https://forum.inductiveautomation.com/t/if-statement-trouble/72681/8 "2023-04-21T00:03:24Z")

</div>

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.
