How to use one script for several buttons

<< Click to Display Table of Contents >>

Navigation:  How To >

How to use one script for several buttons

You want to have a set of buttons that should basically perform a similar action, but a bit different depending on which of the buttons has been pressed.

 

Create some buttons

Create a variable "button_id"

On the OnPress event of each button, set the variable button_id to a certain value (e.g. on button 1 to 1, on button 2 to 2 and so on)

Create one JavaScript

Put the script file on the OnRelease event of each button

In the script use a switch-case statement to differentiate what should happen with which button

 

New since version 2019 of the program:

We have a function called GetCallerID now which tells you in a script from which object the script was executed. So alternatively to the solution above this function could be used in a generic script to find out which button was being pressed.