system.tag.readBlocking() not working correctly

I have this weird issue where Im running a onAction script on a button. I pull 4 binary tags into the code via system.tag.readBlocking("blah blah tag") but when i try to use it in a if statement the code seemingly doesn't work not errors just a flag int i have embedded in code gets to the point where its used.

My work around is assign the tag to a custom prop in the button and then reference this in the code "self.custom.tag" and then the rest of the code executes as expected. Has anyone had this before?

Code Example

tag = system.tag.readBlocking('[PLC]Test/Tags/Tag')
value =  self.getSibling("Table").props.selection.data[0].name
faultInt = 0

if value == "John Smith" and not tag:
   faultInt = 10
else:
   print("Continue")

No matter the conditions i return 10. If i change the "tag" reference to be the custom one as described it all works as intended.

edit* Formatted code for readability as suggested by nminchin.

system.tag.readBlocking returns a list of QualifiedValue, not a basic type. To read a tag value from the results, for example the first tagpath, you need to use something like:

tag[0].value

PS you've also missed an end quote

PPS. if you want to read multiple tags' values, the simplest way is to use:

(tag1,
 tag2,
 ...,
 tagN) = [qval.value for qval in system.tag.readBlocking([
 'tag1Path',
 'tag2Path',
 ...,
 'tagNPath'])
]

PPPS. Use image to format code, otherwise it's unreadable

Also, to diagnose things like this, you can always start by (reading the user manual) printing the type() of the object to the console. You can then see what it is compared to what you expect it to be.
e.g.

system.perspective.print(type(tag))
3 Likes

100% on the money, forget the syntax errors in my post i was just trying to get my issue to words :sweat_smile:

Incorrect eval of the tag reference was def my issue (tag[0].value)

Thanks!