JSup uses code in many places to provide values/conditions/action/etc. to [JSup Animations|animations], [JSup Code script container|script], [JSup Channels|channels], etc.
Normally the code is entered in a [JSup Code multitab control|'''Code multitab control''']:
((([img:///img/JSup/mathCode.png])))
[img:///img/JSup/mathCode-in-textField.png|right|margin=5|]Some [JSup Animations|animations] contain parameter expressions that can only be entered in [JSup Math code|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.
* [JSup Math code|'''Math code''']: for simple mathematics expressions (simply to get the value of a [JSup tag|tag] or combine some tag values in a math expression).
* [JavaCode|'''JavaCode''']: for advanced elaboration and to have access to external Java libraries (for some [JSup Animations|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 [JSup Condition scripts|condition script]).
A code that is used to provide a value (or a condition) to an [JSup Animations|animation] or a [JSup Code script container|script], instead, is executed the '''first time''' (when the [JSup graphic windows|window] that contains the [JSup Animations|animation] code is displayed) and then when a some '''trigger''' [JSup tag|tag] changes its value (see [JSup tag change deadband|tag change deadband] to limit the changes of a [JSup tag|tag]).
* [img:///img/JSup/autoTriggers.png|right|margin=0|]'''Auto triggers''': by default the trigger [JSup tag|tags] are automatically detected in the code content: all the [JSup tag|tag] used in the code (except the [JSup tag|tags] that are used as assignment target). Used [JSup Tag arrays|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.
* [img:///img/JSup/customTriggers.png|right|margin=0|]'''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 [JSup Tag list dialog|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'' [JSup tag|tag] (usually a boolean [JSup Read only tags|read only tag] with no [IOHook|I/O hooks]). ''Custom trigger'' must be used in two different (and opposite) situations:
* The values of the [JSup tag|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 [JSup System tags|system tag] $Second as custom trig.
* The code result depends on some external data (file, database, ...) that is not a [JSup tag|tag]. In such situation, with ''Auto trigger'' mode, the code would never be recalculated. So you can set a ''custom trigger'': the [JSup System tags|system tag] $Second to execute the code once per second, or a [JSup tag|tag] whose value is [Forcing JSup tag value|forced] in a [JSup Timed and triggered scripts|timed script].
=== Code documentation ===
The documentation for the [JSup Math code|Math code] and for [JavaCode] is always available in the ''MathExpression help'' / ''JavaCode help'' tabs of the code control.
* The documentation is in [wikipedia: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.
* [JSup Condition scripts|Condition scripts] - Code that have to be executed when some condition become (or is) true or false.
* [JSup Timed and triggered scripts|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 [JavaCode|JavaCodes] or [JSup Math code|Math code] within the scope of the function [JSup Code script container|container].
* [JSup Key codes|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.