# Scripts Execution

###### WebPage HMI Scripts

These are the WebPages HMI Scripting scripts, such as a Button's On Click event handler script.

For scripts that execute in a web browser:

- Code is edited in the Script Editor.
- Tags are stored at the beginning of the script; if the tag value is updated by another component of the system while the WebPage HMI script is being executed, that change will not affect the tag’s value within the WebPage HMI script. After the WebPage HMI script completes, the updated tag value will be written back to the tag, and will overwrite any other changes to the tag while the WebPage HMI script was executing.

- The use of Promises within the code is supported, and can be used to get the return value of a script and execute any dependent script code.

  Note: Currently, the Script Editor will not raise compile errors when JavaScript code uses Promises in controller scripts. Likewise, the editor will not raise warnings in HMI Web Scripts where the use of $ Functions with a Promise may be preferred. For more information on Promises see the WebPages JavaScript Promises topic.

- The execution of $ Functions and the updating of tags within WebPage HMI scripts are asynchronous to the project being run. There are two different mechanisms for handling asynchronous script execution:

  1. For processes that are tied to controlling parts of the application, bundle the commands in scripts that execute on the controller, such as Data Change Scripts or User Scripts.
  2. Promises can be used to not only force an order of execution, but can also be used to handle values returned from commands executed on the controller. For example, if you wanted to perform a diagnostics check on the controller before displaying a message which is dependent on the returned diagnostic status, or performing an action on the camera that must be completed before operators are allowed to interact with the HMI.