# Boolean set/reset in perspective script

**URL:** <https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [September 25, 2022, 9:02am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453 "2022-09-25T09:02:48Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 25, 2022, 9:02am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/1 "2022-09-25T09:02:48Z")

</div>

It might be silly question, but I encounter issue with set/reset the boolean bit in perspective scripting.  
for example, I want to use toggle button template.  
in a new view, I created the following params  
 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/d/e/de2f746a04c065420e01a6d5b2aee67baf5e8ab8.png)  
then in the button event, i have the following script.  
`self.view.params.tagValue = not self.view.params.tagValue`  
it works.  
But if I change to the following script, it won’t work. It looks like the value has been changed to string type.

```auto
def runAction(self, event):
        currentValue = self.view.params.tagValue
	if currentValue:
		self.view.params.tagValue = "false"
	else:
		self.view.params.tagValue = "true"

```

If I change it to the following, the datatype is changed to numeric, still not working.

```auto
def runAction(self, event):`
	currentValue = self.view.params.tagValue
	if currentValue:
		self.view.params.tagValue = 0
	else:
		self.view.params.tagValue = 1

```

If I change it to the following scripting, it does not even pass the syntax check.  
If I change it to the following, the datatype is changed to numeric, still not working.

```auto
def runAction(self, event):
	currentValue = self.view.params.tagValue
	if currentValue:
		self.view.params.tagValue = false
	else:
		self.view.params.tagValue = true

```

How do I assign boolean data value in perspective script?

It also happened when I read/write the PLC boolean data type, I need to use data transform to transform “true/false” to “0/1” before I can read the value correctly on the view.

Did I missed something? Or is there any way to fix the perspective params to certain data type?

Many thanks in advance.

---

<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:** [September 25, 2022, 9:18am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/2 "2022-09-25T09:18:14Z")

</div>

Tip: use the \</\> code formatting button to preserve code indentation and apply syntax highlighting. It’s essential for Python and makes any code much easier to read. There’s an edit button (pencil icon) below your post so you can fix it.

---

<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:** [September 25, 2022, 9:20am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/3 "2022-09-25T09:20:02Z")

</div>

`self.view.params.tagValue = “false”`  
should be  
`self.view.params.tagValue = False`

`"false"` is a string.  
`False` is a boolean. In Python it’s `True` / `False` and None (null). Capitals matter!

* * *

Note that in Ignition’s Expression Language that case doesn’t matter. See [Expression Language and Syntax - Ignition User Manual 8.1 - Ignition Documentation](https://docs.inductiveautomation.com/display/DOC81/Expression+Language+and+Syntax).

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [September 25, 2022, 3:43pm UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/4 "2022-09-25T15:43:12Z")

</div>

Probably easier to do

```auto
self.view.params.tagValue = not self.view.params.tagValue

```

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 25, 2022, 11:06pm UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/5 "2022-09-25T23:06:07Z")

</div>

Thank you for the reminder.

It works after applying Cap Letter.

Script needs follow Python syntax. But Expression does not. Easy to get confused.

---

<div class="post-metadata">

**Author:** ![justinedwards.jle](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/justinedwards.jle/32/37854_2.png) [@justinedwards.jle](https://forum.inductiveautomation.com/u/justinedwards.jle)\
**Post date:** [September 25, 2022, 11:23pm UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/6 "2022-09-25T23:23:31Z")

</div>

> [@chaoliang](#):
>
> But Expression does not. Easy to get confused.

The property editor also uses lowercase which I feel is a major contributing factor to this common error.

---

<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:** [September 26, 2022, 5:05am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/7 "2022-09-26T05:05:03Z")

</div>

> [@chaoliang](#):
>
> It works after applying Cap Letter.

Good.  
Don't forget to fix the code formatting in your original question. It might help someone else in the future.

---

<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:** [September 26, 2022, 4:09pm UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/8 "2022-09-26T16:09:54Z")

</div>

> [@justinedwards.jle](#):
>
> The property editor also uses lowercase which I feel is a major contributing factor to this common error.

No winning there. The property editor displays JSON. Java and Javascript (and thus JSON, **J** ava **s** cript **O** bject **N** otation) use `true` and `false`. No matter what we pick, it's going to confuse _someone_.

---

<div class="post-metadata">

**Author:** ![chaoliang](https://avatars.discourse-cdn.com/v4/letter/c/ba8739/32.png) [@chaoliang](https://forum.inductiveautomation.com/u/chaoliang)\
**Post date:** [September 29, 2022, 6:25am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/9 "2022-09-29T06:25:59Z")

</div>

applied the formatting button, but the indentation was not preserved.

---

<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:** [September 29, 2022, 7:03am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/10 "2022-09-29T07:03:35Z")

</div>

You seem to have applied it line by line which results in a each line enclosed in single backticks. Select a whole block of code and press the \</\> button. You should get a result like

````auto
    ```
    <code goes here>
    ```

````

---

<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:** [September 29, 2022, 7:12am UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/11 "2022-09-29T07:12:17Z")

</div>

You can even tell it what language to use for syntax highlighting:

```python  
\<code goes here\>  
```

Side note, I’ve gotten used to start scripts in the script console with

```python
false = False
true = True

```

So I don’t have surprises when I paste in some json from a component’s property.

---

<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:** [September 29, 2022, 12:51pm UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/12 "2022-09-29T12:51:03Z")

</div>

> [@pascal.fragnoud](#):
>
> So I don’t have surprises

Oy! But the next guy is toast.

---

<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:** [September 29, 2022, 12:52pm UTC](https://forum.inductiveautomation.com/t/boolean-set-reset-in-perspective-script/64453/13 "2022-09-29T12:52:38Z")

</div>

No one else is going to use my script console. I’d bite if someone tried to touch my keyboard.
