Button counter when is clicked and show it in a label

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:

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.

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.


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:

    self.custom.holdNo += 1  

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