Variables and functions

Variables

Functions

 

The fact that BrainVoyager QX is scripting-enabled means that many of the functions that are available in the menu can be also invoked by scripting. To use this scripting option, the scripting environment has to be started.

 

Variables
All variables are declared with the var identifier. This means that the scripting module will figure out itself whether a variable represents a string value ("MyFMRProjectName"), a number (3.14) or a boolean (true or false).

To assign a value to the variable, the '=' sign can be used. The value should be on the right side of the statement, and the name of the variable on the left side:  var FMRprojectName = "My3TfacesAndHousesProject.fmr";

 

QSA objects need to be created via the new parameter, for example var talFile = new File('C:/MyData/landmarks.tal');. Except for some of the QSA Object classes, that do not need to be instantiated. This is the case for the MessageBox, FileDialog and Input classes. They can be used directly , for example var fileName = FileDialog.getOpenFileName(); The new keyword is omitted here.

 

See also the Trolltech documentation on variables.

 

 

Functions
In QSA some built-in functions are available. With these functions it is easier to create your own functions. A function declaration should look like this:

function   nameOfFunction( ) {  

statements;  

}

 

 

So in case the function should compute the factorial, this could be formulated in the following way:

 


 

This function can be used in another function by using its name, and passing the parameter, if required. In the example the number '12' is passed to the function 'factorial()'. The 'testFactorial()' function generates a messagebox with the parameter that it received from the function 'factorial()'.

 

 

 

Next: 1. Basics of scripting in BrainVoyager QX (continued)
Index