# JavaScript continuous

Definition

A custom variable that processes raw data (for example, the subject coordinates, or the distance moved) and produces a numeric value for each sample of the track, based on an algorithm.

The JavaScript continuous variable outputs a rational number; other solutions are possible with JavaScript state (with a duration) and JavaScript event (with no duration). See Commands and functions for JavaScript variables

Use Cases

▪Subject counter. Count the number of subjects currently present in a zone. For example: How many fish swim at the top of the tank? How many fruit flies enter each side of the T-maze?

▪Subject counter. Calculate the ratio between the number of subjects in zone A to the number of subjects in zone B.

▪Body length. Calculate the body length as the distance of the nose-point to the tail-base point.

▪Tail beat detector. Calculate the ratio between the distance moved by the tail-base and the distance moved by the center-point. This helps quantify tail beats in fish.

▪tip Browse to my.noldus.com, log in or register and choose Downloads > EthoVision XT > Drivers and tools. There you can download examples of JavaScript continuous variables. Simply copy the code to the JavaScript Continuous window in EthoVision XT (see below).

To specify a JavaScript continuous variable

1.In the Analysis profile, under Custom Variables, click the button next to JavaScript continuous.

2.In the JavaScript Continuous window, enter the code you require.

important Always specify the following functions: Start(), Stop() and Process(), even when they do not include code lines. See the figure above as an example.

3.Click Check to see if there are syntax errors. Note that this check is not thorough and does not guarantee that the code provides meaningful data.

4.Complete the procedure to add the variable. See Calculate statistics: procedure

Notes

▪When you use functions like GetCenter, the coordinates are given in millimeters no matter what your measurement units is selected in the Experiment Settings. Therefore, all calculations based on coordinates are given in millimeters. If your calibration is done in cm, divide the results by ten; similarly, values of subject area obtained with the function GetArea are in mm2.

▪Select a Number of outputs other than 1 if the JavaScript variable is made of two or more outputs. For example, suppose your code creates three state outputs for b1, b2, b3:

SetOutput(0, b1);

SetOutput(1, b2);

SetOutput(2, b3);

Then select 3 as Number of outputs. The value of each output is updated at each sample.

▪JavaScript is not the same thing as Java. Although the two programming languages may show similarities in the syntax, there are profound differences, for example in the rules that govern how variables and functions work.

▪EthoVision XT uses the Internet Explorer 11-compatible JavaScript engine. This engine does not support the following features:

▪Strict equality operators, for example '===' or '!=='.

▪Class expression (classes are only available through function expressions).

▪Arrow function expression.

▪Fill for arrays.

▪the Math.hypot function.

See also

▪JavaScript event

▪JavaScript state

▪Commands and functions for JavaScript variables