# Toggling the setValue on a Button

**URL:** <https://forum.inductiveautomation.com/t/toggling-the-setvalue-on-a-button/110139>\
**Category:** Ignition\
**Tags:** perspective, scripting\
**Created:** [August 25, 2025, 6:42am UTC](https://forum.inductiveautomation.com/t/toggling-the-setvalue-on-a-button/110139 "2025-08-25T06:42:32Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![sfatimazahrak](https://avatars.discourse-cdn.com/v4/letter/s/c2a13f/32.png) [@sfatimazahrak](https://forum.inductiveautomation.com/u/sfatimazahrak)\
**Post date:** [August 25, 2025, 6:42am UTC](https://forum.inductiveautomation.com/t/toggling-the-setvalue-on-a-button/110139/1 "2025-08-25T06:42:32Z")

</div>

I am trying to add a functionality to my button so that i can use it to set something to 1, and then to 0 when pressed again. Im trying to use a change script on the Value property for this, but am constantly getting an error. What am i doing wrong

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/c/4/c463f992c2e9553b711633a5b9348f43586e616b.png)

---

<div class="post-metadata">

**Author:** ![nminchin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/nminchin/32/6911_2.png) [@nminchin](https://forum.inductiveautomation.com/u/nminchin)\
**Post date:** [August 25, 2025, 6:46am UTC](https://forum.inductiveautomation.com/t/toggling-the-setvalue-on-a-button/110139/2 "2025-08-25T06:46:20Z")

</div>

Things like this can be explained by AI, just make sure you tell it what language it is (ie jython or python).

The issue however is your if statement syntax. You're using expression language syntax and not python.

You need to use:

```python
if currentValue.value:
 self.props.setValue = 1
else:
 self.props.setValue = 0

```

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [August 25, 2025, 6:52am UTC](https://forum.inductiveautomation.com/t/toggling-the-setvalue-on-a-button/110139/3 "2025-08-25T06:52:20Z")

</div>

If it's a boolean then Nick's code can be reduced to:  
`return not currentValue.value`  
(A boolean will use True / False rather than 1 / 0.)

If you are doing this as a transform on a binding then you should avoid the transform and do it all directly in an Expression Binding.  
`if({tagOrPropertyToBeMonitored}, false, true)`  
which can be reduced to,  
`!{tagOrPropertyToBeMonitored}`

Note the `!` negation at the start.

---

<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:** [August 25, 2025, 6:55am UTC](https://forum.inductiveautomation.com/t/toggling-the-setvalue-on-a-button/110139/4 "2025-08-25T06:55:51Z")

</div>

Don't use a value change script for this.  
Read the value from the button script, compute the value you should be writing depending on what it currently is, then write that back.

```python
current_val = path.to.your.prop
if current_val = 0:
    new_val = 1
else:
    new_val = 0
path.to.your.prop = new_val

```

or, in a more concise manner:

```python
path.to.your.prop = 1 - path.to.your.prop

```

If it's a boolean, which it probably should be considering it can take only 2 values, then it's even simpler:

```python
path.to.your.prop = not path.to.your.prop

```
