Calling a timer script via button trigger event

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!

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

Yeah, that is my intention. The script only runs every three seconds after pressing the button. I used timer script for looping a certain amount of time.

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.

2 Likes

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?

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

1 Like

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?

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

1 Like

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.