Skip to content

HowTo configure Script

matt303 edited this page Nov 19, 2024 · 2 revisions

To configure scripts going to Scripts in editor.

Add a new script (a script is a javascript function), configure the function name and parameters, there are 2 type of parameters:

  • Tag ID
  • Value, number or string

Then you write your logic into the function. There are system call that you can use:

  • $setTag, to set value of Tag
  • $getTag, to get current Tag value

You can test the script, to verify it makes sense to use the console.log method.

From the GUI you can configure in Events the call of script.

If you use intervals in a script it's important you handle them correctly. For example if you have setInterval in a script and run the test multiple times this will create a new interval each time calling the same piece of code and you will have to restart Fuxa to clear it. One method to handle this is assign an ID to the interval and do a simple check if it exist.

if (typeof globalThis.myTimer === 'undefined') globalThis.myTimer = null;

if (!globalThis.myTimer) globalThis.myTimer = setInterval(myTimerFunction, 1000);

async function myTimerFunction() {
  //myTimer code here every 1 sec
}