JSup uses code in many places to provide values/conditions/action/etc. to animations, script, channels, etc.
Normally the code is entered in a Code multitab control:
Some animations contain parameter expressions that can only be entered in Math code language in simple text fields (see the picture on the right).
Code languages
The code in JSup can be entered in two different language.
- Math code: for simple mathematics expressions (simply to get the value of a tag or combine some tag values in a math expression).
- JavaCode: for advanced elaboration and to have access to external Java libraries (for some animations of for JavaCode functions the JavaCode language is the only allowed).
Code execution
An Action code is executed when the user, for example, presses a button, or when a condition is met (for a condition script).
A code that is used to provide a value (or a condition) to an animation or a script, instead, is executed the first time (when the window that contains the animation code is displayed) and then when a some trigger tag changes its value (see tag change deadband to limit the changes of a tag).
Auto triggers: by default the trigger tags are automatically detected in the code content: all the tag used in the code (except the tags that are used as assignment target). Used tag array elements are dynamically detected and looked for changes. This is the simplest way and, in 99% of the situations, is right one. Auto trigger recalculate the code when any of the contained tag value changes.
Custom triggers must be provided when the Auto triggers checkbox is not selected. To select them you have to move to the Custom trigger tab. Then press the Add button and selected the trigger from the tag list dialog. At least one custom trigger must be provided. If you want the code to be never triggered then you can add a never triggered tag (usually a boolean read only tag with no I/O hooks). Custom trigger must be used in two different (and opposite) situations:
- The values of the tags used in the code change to often, and you want to limit the times the code is executed in a second. So you can decide to executed the code only once in a second and you can set the system tag $Second as custom trig.
- The code result depends on some external data (file, database, ...) that is not a tag. In such situation, with Auto trigger mode, the code would never be recalculated. So you can set a custom trigger: the system tag $Second to execute the code once per second, or a tag whose value is forced in a timed script.
Code documentation
The documentation for the Math code and for JavaCode is always available in the MathExpression help / JavaCode help tabs of the code control.
- The documentation is in
HTML format, so you can click the hyperlinks to change the displayed page and Alt+left/right arrows to go back/forward in the page history.
- You can maximize the documentation text to full screen with a double right click of the mouse.
Code locations
- JSup Code script container - Active codes - Code executed on application startup/shutdown or window show/hide and (de)activation.
- Condition scripts - Code that have to be executed when some condition become (or is) true or false.
- Timed and triggered scripts - Code to be executed on tag value change or when some timeout has elapsed.
- JavaCode functions - Utility functions that can be used by other JavaCodes or Math code within the scope of the function container.
- Key codes - Scripts that will be invoked when the given key combinations are pressed.
- JavaCode common - A place where to define global (static) variable/object to be used within the scope of the container. See JavaCode functions for better way to define static variable to be used by your code in more exportable/importable way.