# Button counter when is clicked and show it in a label

**URL:** <https://forum.inductiveautomation.com/t/button-counter-when-is-clicked-and-show-it-in-a-label/84823>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [January 26, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/button-counter-when-is-clicked-and-show-it-in-a-label/84823 "2024-01-26T17:23:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Leandro\_Garcia\_Carva](https://avatars.discourse-cdn.com/v4/letter/l/6f9a4e/32.png) [@Leandro\_Garcia\_Carva](https://forum.inductiveautomation.com/u/Leandro_Garcia_Carva)\
**Post date:** [January 26, 2024, 5:23pm UTC](https://forum.inductiveautomation.com/t/button-counter-when-is-clicked-and-show-it-in-a-label/84823/1 "2024-01-26T17:23:40Z")

</div>

I am using a button to increase a step count in Perspective. What I want to do is take a value from this button, use the button to increment the value and then write the new value to a label. I have been trying to do this but the message below appears:

com.inductiveautomation.ignition.common.script.JythonExecException  
Traceback (most recent call last):  
File "function:runAction", line 2, in runAction  
UnboundLocalError: local variable 'holdNo' referenced before assignment

My script is below. I know its wrong!

holdNo = holdNo + 1  
self.getSibling(Label\_0).props.text = holdNo

Sorry I know its very basic, but I don`t know how.  
Regards,  
Leandro

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [January 26, 2024, 5:25pm UTC](https://forum.inductiveautomation.com/t/button-counter-when-is-clicked-and-show-it-in-a-label/84823/2 "2024-01-26T17:25:56Z")

</div>

You are referencing `holdNo` before you define it. If I asked you to set the variable `a=a+1` you could do it - but only if you knew what `a` was first.

I would suggest taking a short course on python if you are not familiar with it along with Inductive University for Ignition specific knowledge.

Basically you have to tell your script an initial value for `holdNo` before you add 1 to it.

---

<div class="post-metadata">

**Author:** ![cmallonee](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/cmallonee/32/6416_2.png) [@cmallonee](https://forum.inductiveautomation.com/u/cmallonee)\
**Post date:** [January 26, 2024, 6:58pm UTC](https://forum.inductiveautomation.com/t/button-counter-when-is-clicked-and-show-it-in-a-label/84823/3 "2024-01-26T18:58:00Z")

</div>

You can avoid writing to the Label at all. place a custom property on the button: `Button.custom.holdNo`. Give that property a numeric value to start with when the View loads (probably `0`).

Change your script to this:

```python
    self.custom.holdNo += 1  

```

Then bind the text of the Label to that custom property.
