# Script to make tag value True not working?

**URL:** <https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [December 4, 2023, 3:06am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650 "2023-12-04T03:06:21Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![SB\_Ireland](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SB\_Ireland](https://forum.inductiveautomation.com/u/SB_Ireland)\
**Post date:** [December 4, 2023, 3:06am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/1 "2023-12-04T03:06:21Z")

</div>

![Screenshot 2023-12-04 025749](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/4/e4f5f10e436c120e923b78e1b6cf69f122076416.png)  
So, in short I am new to ignition and python(what a baptism of fire). I am doing a replica scada screen of my workplace to familiarize myself with the system before even going near the already working one.  
On previous scada systems I have used the same code to read the value and depending on conditions, set a Boolean value. the exact situation is a tank. If the level of the tank should go above 90%, a Boolean tag should be made true. I had specific tags made for this but since starting this nothing seems to work. Am i even putting the script in the right place? the code seems ok and have verified with Pycharm but nothing comes of it. I have tried the code in the event gateway under the timer section and it was enabled. since then i have retreated back to writeable tags.  
Any help would be greatly appreciated and any recommendations on someone who does videos for this would be incredible.  
Thank you and apologies

---

<div class="post-metadata">

**Author:** ![Learner\_Ignition](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Learner\_Ignition](https://forum.inductiveautomation.com/u/Learner_Ignition)\
**Post date:** [December 4, 2023, 3:48am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/2 "2023-12-04T03:48:03Z")

</div>

Hi,  
Why you are not using `currentValue` in the condition?  
and **tagPath** and **value** should be of list type.

---

<div class="post-metadata">

**Author:** ![SB\_Ireland](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SB\_Ireland](https://forum.inductiveautomation.com/u/SB_Ireland)\
**Post date:** [December 4, 2023, 4:00am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/3 "2023-12-04T04:00:41Z")

</div>

I had used currentvalue previous to this and it did not. Should this code not work by itself? It applies with no errors and nothing happens when the integer value goes above the 90 setpoint. The tagpath is just one tag. So there wont be a list? Again very new to this

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [December 4, 2023, 4:02am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/4 "2023-12-04T04:02:10Z")

</div>

Make lists of length == one for your tag path and corresponding value.

---

<div class="post-metadata">

**Author:** ![Learner\_Ignition](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Learner\_Ignition](https://forum.inductiveautomation.com/u/Learner_Ignition)\
**Post date:** [December 4, 2023, 4:06am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/5 "2023-12-04T04:06:08Z")

</div>

[system.tag.writeBlocking - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/system.tag.writeBlocking#:~:text=List%C2%A0tagPaths%C2%A0%2D%C2%A0A%20List%20of%20Tag%20paths%20to%20write%20to.%20If%20no%20property%20is%20specified%20in%20a%20Tag%20path%2C%20the%20Value%20property%20is%20assumed).

Check the example also

---

<div class="post-metadata">

**Author:** ![SB\_Ireland](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SB\_Ireland](https://forum.inductiveautomation.com/u/SB_Ireland)\
**Post date:** [December 4, 2023, 4:21am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/6 "2023-12-04T04:21:27Z")

</div>

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/e/b/eb2ab7aa72e3771a0aabf127d312763ea4d31955.png)

I removed the first line and changed line 3 to match Learner\_Ignition suggestion. It worked and I am not sure why the first line would have caused an issue. Thanks for you for the help. Sometimes browsing the manuals and the DOC81 just confuses me more

---

<div class="post-metadata">

**Author:** ![Learner\_Ignition](https://avatars.discourse-cdn.com/v4/letter/l/b3f665/32.png) [@Learner\_Ignition](https://forum.inductiveautomation.com/u/Learner_Ignition)\
**Post date:** [December 4, 2023, 4:30am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/7 "2023-12-04T04:30:03Z")

</div>

Did you change tagPath and value to be of list??

---

<div class="post-metadata">

**Author:** ![SB\_Ireland](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SB\_Ireland](https://forum.inductiveautomation.com/u/SB_Ireland)\
**Post date:** [December 4, 2023, 4:39am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/8 "2023-12-04T04:39:27Z")

</div>

No. Should I? I dont quite understand why? Can you show me the code or explain the benefit?

---

<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:** [December 4, 2023, 4:41am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/9 "2023-12-04T04:41:00Z")

</div>

> [@SB\_Ireland](#):
>
> It worked and I am not sure why the first line would have caused an issue

`system.tag.readBlocking` unconditionally returns a _list_. So even if you only read one tag, you still have to unpack the values by retrieving the `QualifiedValue` at the 0th index, _then_ retrieve the `.value` attribute of the `QualifiedValue`:  
`value = system.tag.readBlocking("someTagPath")[0].value`

But as pointed out, using `currentValue.value` is significantly more performant and a bit nicer to read.

As an additional point of confusion (sorry) for everyone:  
`system.tag.writeBlocking` and `system.tag.readBlocking` _can_ accept single input parameters, but are _intended_ to be used with lists (and you should probably get in the habit of using lists). (The rationale was that it was going to be easier to gloss over this point in training classes, rather than getting hung up on the list inputs. In practice it may not have been worth the headaches 🤷‍♂️)

So, _functionally_, these two are equivalent:  
`system.tag.readBlocking("someTagPath")`  
`system.tag.readBlocking(["someTagPath"])`  
As well as these two:  
`system.tag.writeBlocking("someTagPath", someValue)`  
`system.tag.writeBlocking(["someTagPath"], [someValue])`

They are not the same semantically, and there is absolutely a difference in terms of Jython. But the system functions are _just_ "smart" enough to automatically wrap a single input into a list "under the hood" - that's why you can get away with your writeBlocking usages.

As a further aside, you can simplify your script a fair amount by reducing the comparison to a single boolean expression.  
That is:

```python
if condition:
    doSomething(True)
else:
    doSomething(False)

```

Could be just as well written as:

```python
doSomething(condition)

```

As in:

```python
system.tag.writeBlocking(["[default]_Sample_Device_/Writeable/WriteableBoolean2"], [currentValue.value >= 90])

```

Is **exactly** equivalent to your current code, but has the benefit of making it immediately obvious that no matter which branch is hit, you're always writing to the same output tag.

---

<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:** [December 4, 2023, 11:03am UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/10 "2023-12-04T11:03:14Z")

</div>

Also...  
I believe you don't need a script at all.  
If you make your `writeableboolean2` tag an expression tag instead, you can bind its value to an expression using `writeableinteger1`.

A very simple expression is enough:  
`[.]writeableinteger1 >= 90`

Note the dot in the brackets: it means it uses a relative path. That's very neat if you need to repeat the same thing, like in a UDT.

edit: example:  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/1/8/1846b61b5fef76dc4b60641c8ed5f3dd9f81500c.png)

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

![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/0/b/0b6577830d84671506360b57d8991f3384e1b3fb.png)

---

<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:** [December 4, 2023, 3:38pm UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/11 "2023-12-04T15:38:08Z")

</div>

> [@pascal.fragnoud](#):
>
> If you make your `writeableboolean2` tag an expression tag instead, you can bind its value to an expression using `writeableinteger1`.

Definitely true in the general case, but these are OPC tags from the simulator device, so it's not quite so straightforward.

---

<div class="post-metadata">

**Author:** ![SB\_Ireland](https://avatars.discourse-cdn.com/v4/letter/s/97f17d/32.png) [@SB\_Ireland](https://forum.inductiveautomation.com/u/SB_Ireland)\
**Post date:** [December 4, 2023, 3:58pm UTC](https://forum.inductiveautomation.com/t/script-to-make-tag-value-true-not-working/82650/12 "2023-12-04T15:58:04Z")

</div>

Thank you! I think i need to start an actual training course on this. As I will be eventually taking values from a Siemens s7-1200 plc
