# Calling a timer script via button trigger event

**URL:** <https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024>\
**Category:** Ignition\
**Tags:** perspective\
**Created:** [November 12, 2021, 4:33pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024 "2021-11-12T16:33:57Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![phandc](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phandc](https://forum.inductiveautomation.com/u/phandc)\
**Post date:** [November 12, 2021, 4:33pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/1 "2021-11-12T16:33:58Z")

</div>

Hi everyone,  
I have a button and a time script in the Gateway event of the Scripting. By default, the timer script will run every 3 seconds in the Gateway. I don’t want that script to run like that. I want to attach it to a button trigger event. When a user clicks on the button, it will start calling a script.

Thank you so much for your time!

---

<div class="post-metadata">

**Author:** ![awaege1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awaege1/32/28922_2.png) [@awaege1](https://forum.inductiveautomation.com/u/awaege1)\
**Post date:** [November 12, 2021, 4:42pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/2 "2021-11-12T16:42:32Z")

</div>

Is the intention here to have the script start running every three seconds after pressing the button?

---

<div class="post-metadata">

**Author:** ![phandc](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phandc](https://forum.inductiveautomation.com/u/phandc)\
**Post date:** [November 12, 2021, 4:55pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/3 "2021-11-12T16:55:12Z")

</div>

Yeah, that is my intention. The script only runs every three seconds after pressing the button. I used [timer script](https://docs.inductiveautomation.com/display/DOC80/Gateway+Event+Scripts) for looping a certain amount of time.

---

<div class="post-metadata">

**Author:** ![awaege1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awaege1/32/28922_2.png) [@awaege1](https://forum.inductiveautomation.com/u/awaege1)\
**Post date:** [November 12, 2021, 5:01pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/4 "2021-11-12T17:01:09Z")

</div>

In that case you will need to be careful how you implement your solution. Since the timer script is a gateway event, one user hitting the button on the client end would have the effect of updating all client devices instead of just the one that pushed the button.

My suggestion would be to do as follows:

Use the timer script to create a boolean pulse that pulses every three seconds on each individual client. Then create a second boolean flag to act as your input from the button. Finally create an expression structure binding on a property that is bound to both the pulse boolean and your button boolean and set a script transform on that binding to fire only when both are true.

Doing it this way allows you to keep your script execution on the client side while also keeping your timer functionality as desired.

---

<div class="post-metadata">

**Author:** ![phandc](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phandc](https://forum.inductiveautomation.com/u/phandc)\
**Post date:** [November 12, 2021, 5:19pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/5 "2021-11-12T17:19:21Z")

</div>

Thanks for your suggestion.  
Actually, I have a mode and the timer script only runs when the mode is on. Your suggestion is helpful.  
I could understand the idea but I don’t know where I can bind the expression structure and add a script transform for it as you mentioned above. Could you show me an example?

---

<div class="post-metadata">

**Author:** ![awaege1](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/awaege1/32/28922_2.png) [@awaege1](https://forum.inductiveautomation.com/u/awaege1)\
**Post date:** [November 12, 2021, 5:24pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/6 "2021-11-12T17:24:41Z")

</div>

The best place would be to create a custom session property or a custom property on the view you are running the button on and then bind to that property

---

<div class="post-metadata">

**Author:** ![phandc](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phandc](https://forum.inductiveautomation.com/u/phandc)\
**Post date:** [November 12, 2021, 5:54pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/7 "2021-11-12T17:54:01Z")

</div>

Thanks for your help.  
I would like to expand the topic. Actually, I want to run a script every certain amount of time. I find the timer script is a way to do handle it. I also consider threading or coroutine when a user clicks the button event. Could you give some advice about that?

---

<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:** [November 12, 2021, 7:31pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/8 "2021-11-12T19:31:07Z")

</div>

Put the script in a project library. You can then call it from either a gateway script or a button click.

---

<div class="post-metadata">

**Author:** ![phandc](https://avatars.discourse-cdn.com/v4/letter/p/ce73a5/32.png) [@phandc](https://forum.inductiveautomation.com/u/phandc)\
**Post date:** [November 13, 2021, 4:27pm UTC](https://forum.inductiveautomation.com/t/calling-a-timer-script-via-button-trigger-event/53024/9 "2021-11-13T16:27:03Z")

</div>

Yeah, I have already written a script then called it from a timer script. The problem here is how to implement it without using timerscript and manage the performance efficiently.
