User Tools

Site Tools


debugging_complex_programs

This is an old revision of the document!


Debugging complex scripts

Project initialization

Non - volatile registers

Please keep in mind that registers of Dxx type and some other internal registers, except for DSxx, Sxx return to the initial state (usually 0) after initialization of the project (what happens with any editing of project elements - scripts, registers, connections, etc.). If such registers are used as variables to generate event triggers or conditions for executing other scripts, this can lead to a violation of the execution logic. You should consider this feature when choosing registers as input and output script variables.

Global variables

Variables in scripts declared before the 'main' function store their values ​​between script calls, but also reset when initializing. They can be used to store constants, coefficients, and other similar values.

First scan

Some script can be assigned to run on the first scan when the project is initialized and make some initialization of variables from one place. Sometimes you might need to define inside the script itself whether this was the first call after initialization. You can create a global variable first_scan:

<code lua> first_scan = true – global var remember value between scans function main (userId) local var = 0 – local var will be initialized in each script call

if first_scan then 
   first_scan = false
   -[[

Actions for the first scan

  1. -]]

end –if first_scan – other actions end – main <code>

Remember that registers such as Dxx, CDxx and other internal registers, except for DSxx, return to the initial state (usually 0) after initializing the project (which happens when editing project elements - scripts, registers, connections, etc.). If such registers are used as variables to generate event triggers or conditions for executing other scripts, this can lead to a violation of the execution logic. You should consider this feature when choosing registers as input and output script variables.

debugging_complex_programs.1545821446.txt.gz · Last modified: 2018/12/26 10:50 by emozolyak

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki