{{ network:menu-icon-scripts.png?direct&40}} ===== Scripts Editor ===== Script editor allows you to write and manage scripts. - Script list - Selected script properties area - Code editor area - Edit tool buttons (full screen, insert function calls, show/hide console window, save) - Create new script button - Debbuging console As of 4.0 fw verstion there is a global search box above the script list: {{ :lua:script_global_search_box.png?direct&400 |}} The main editor's window: {{ :lua:script_editor_standard_view_numbered.png?direct&912 |}} ==== Script list (1) ==== {{ network:modified_disabled_script2.png?600 |}} In the example list provided, the script titles are named as accroding to their possible execution types. Two or three icons indicates execution type of script (see more details below), wether it has modifications, and its running state (Enabled/Disabled). The scripts run in the order how they are sorted in the list. This order can be easily changed by dragging a script into a new location. The line starts with the script **Id**. This number is shown in communication log to track the relevant script. E.g. Jul 26 17:23:27.450: ERROR: LUA scripts: Can't execute LUA script #3. ==== Property area (2) ==== You can set here **name** for the script, select **type**, **disable** or **enable** it and give short **description**. There are 6 types of scripts: ***Execute in every loop** - script runs in every scan after reading registers in connections ***Script for dashboard** - script runs upon clicking the button with this script “attached” to it ***Execute on register's value change** - if there is difference of the register's value read in previous and current scan then script will be executed ***Script for calendar** - the script is set as start or end task action in the calendar ***Execute once on project start** - runs one time on the very first scan during project start ***Library for other programs** - the library body is included into another scritps with the command --[[ Please note that library code should have only functions and variable declaration, not the main() function.--]] include "myLibName" ==== Editor (3) ==== WebHMI has handy code editor with useful features: * syntax highlighting * code completion * syntax validation * debugging console * supports a number of typical hotkeys Table of popular hotkeys: ^Key^Function^ |F6|toggle compact / full-screen mode | |Crtl-S|save the script | |Ctrl-F|find and highlight occurence | |Ctrl-H|find and replace | |Ctrl-Z|undo | |Ctri+Shift-Z|redo | |Ctrl-A|select all | |Ctrl-L|Select specific line | |Ctrl-D|delete line | |Ctrl-[ or Shift-Tab|decrease indent | |Ctrl-] or Tab |increase indent | |Ctrl-U|convert text to upper case | For more hotkeys, please refer to the Ace code editor. ==== Editor toolbar (4) ==== The toolbar has the following buttons (from left to right): *Toggle full / compact screen mode button (hotkey: **F6**) *Insert GetReg call (will be explained further in GetReg function details) *Insert SetReg call *Insert WriteReg call *Show/hide console button *Save script (hotkey **Ctrl-S**) *Decrease the code font size (s ∨) *Increase the code font size (S ^) *Clone script button *Delete script button In the following picture, the full editor mode with console activated is shown: {{ :lua:script_editor_new_toolbar.png?direct&912 |}} ==== Adding script (5) ==== When there are no scripts yet in the project, the **+Add script** button is placed in the page center. After adding a script it is moved to the top-right page corner. ==== Debugging console (6) ==== The console has two controls: - You can drag the top border to change the console size - You can run/stop output to console with the run/stop button in the top right corner. {{ :lua:script_editor_just_console.png?direct&912 |}}