# Typecasting / coercion?

**URL:** <https://forum.inductiveautomation.com/t/typecasting-coercion/10296>\
**Category:** Ignition\
**Created:** [July 31, 2015, 3:04pm UTC](https://forum.inductiveautomation.com/t/typecasting-coercion/10296 "2015-07-31T15:04:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JoeJansen](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/joejansen/32/5277_2.png) [@JoeJansen](https://forum.inductiveautomation.com/u/JoeJansen)\
**Post date:** [July 31, 2015, 3:04pm UTC](https://forum.inductiveautomation.com/t/typecasting-coercion/10296/1 "2015-07-31T15:04:33Z")

</div>

I’m trying to do the following in a project script:

`def debugTest():
	tester = system.tag.read("[Client]prevSt")
	tester=tester + 1
	system.tag.write("[Client]prevSt",tester) `

but I get:

[code]Traceback (most recent call last):  
File “”, line 1, in   
File “module:project.stateMachine”, line 17, in debugTest  
TypeError: unsupported operand type(s) for +: ‘com.inductiveautomation.ignition.common.sqltags.BasicTagValue’ and ‘int’

[/code]

The help file speaks of the toInt command when looking to do typecasting. A bit of rearranging gives me:

`def debugTest():
	tester = system.tag.read("[Client]prevSt")
	intTester=toInt(tester) + 1
	system.tag.write("[Client]prevSt",intTester) `

Brilliant, yes?

No:

[code]Traceback (most recent call last):  
File “”, line 1, in   
File “module:project.stateMachine”, line 17, in debugTest  
NameError: global name ‘toInt’ is not defined

[/code]

So how do I read a tag of type int, add one to it, and write it back from within a project script? This should be scripting 101, but I am at a loss.

Thanks!

Joe

---

<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:** [July 31, 2015, 3:27pm UTC](https://forum.inductiveautomation.com/t/typecasting-coercion/10296/2 "2015-07-31T15:27:17Z")

</div>

The value you get back from system.tag.read is a “qualified value”, a structure that contains the value, quality, and timestamp. You need to access the value attribute before attempting to use it the way you are.

---

<div class="post-metadata">

**Author:** ![nmudge](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nmudge/32/3394_2.png) [@nmudge](https://forum.inductiveautomation.com/u/nmudge)\
**Post date:** [July 31, 2015, 3:38pm UTC](https://forum.inductiveautomation.com/t/typecasting-coercion/10296/3 "2015-07-31T15:38:44Z")

</div>

Hi,  
Kevin is right. It should be like this.

```auto
def debugTest():
   tester = system.tag.read("[Client]prevSt").value
   tester=tester + 1
   system.tag.write("[Client]prevSt",tester)
```

Notice that the “value” property was used.
