# An if cycle with a boolean

**URL:** <https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015>\
**Category:** General Discussion\
**Created:** [August 8, 2016, 8:03pm UTC](https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015 "2016-08-08T20:03:31Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![P11](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@P11](https://forum.inductiveautomation.com/u/P11)\
**Post date:** [August 8, 2016, 8:03pm UTC](https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015/1 "2016-08-08T20:03:31Z")

</div>

Please, I need help with scripting. My objective is to change manually a boolean variable, then when this variable changes, another tag has to assume a fixed value, 40 if the boolean is set to true, false when it is set to 0. What I have to do ? I have tryed this

if “verofalso” == 1:  
system.tag.write(‘verofalso1’,40)  
else: system.tag.write(‘verofalso1’,0)

Thank you in advance for your answers.

---

<div class="post-metadata">

**Author:** ![JordanCClark](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jordancclark/32/83362_2.png) [@JordanCClark](https://forum.inductiveautomation.com/u/JordanCClark)\
**Post date:** [August 8, 2016, 8:44pm UTC](https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015/2 "2016-08-08T20:44:47Z")

</div>

Hi! Welcome to the forums!  
If this is a tag change script, you also need to specify the tag provider, even if it is the default one:

`if "verofalso" == 1:
  system.tag.write('[default]verofalso1',40)
else: 
  system.tag.write('[default]verofalso1',0)
`

A side note: if you wrap your code within the Code Tags using the button above the editor, it makes your code easier to read… 🙂  
[attachment=0]2016-08-08\_16-40-54.png[/attachment]

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [August 9, 2016, 1:36pm UTC](https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015/3 "2016-08-09T13:36:39Z")

</div>

```auto
if "verofalso" == 1:
```

You are also comparing the string “verofalso” to the integer 1 which will always be false.

---

<div class="post-metadata">

**Author:** ![pphillips](https://avatars.discourse-cdn.com/v4/letter/p/da6949/32.png) [@pphillips](https://forum.inductiveautomation.com/u/pphillips)\
**Post date:** [August 9, 2016, 1:53pm UTC](https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015/4 "2016-08-09T13:53:22Z")

</div>

So if I understand this correctly, what you want to do would look something like this:

```auto
value = system.tag.read('[default]verofalso').value

if value == 1:
    system.tag.write('[default]verofalso1', 40)
else:
    system.tag.write('[default]verofalso1', 0)
```

---

<div class="post-metadata">

**Author:** ![P11](https://avatars.discourse-cdn.com/v4/letter/p/a9adbd/32.png) [@P11](https://forum.inductiveautomation.com/u/P11)\
**Post date:** [August 11, 2016, 9:07am UTC](https://forum.inductiveautomation.com/t/an-if-cycle-with-a-boolean/12015/5 "2016-08-11T09:07:35Z")

</div>

Thank you a lot guys 😃
