[[TOC]] The !JavaScript engine of dimctrl is fully based on Google's V8 which you find for example in their Browser. The advantage is two-fold. It is basically a well maintained product, and it can be embedded into our own structure, e.g. any script can be terminated at any time without the need to foresee that case in the script. !JavaScript references can be found her: * [http://www.w3schools.com/jsref/default.asp w3schools] (//!JavaScript objects//) * [https://developer.mozilla.org/en-US/docs/JavaScript/Reference Mozilla] * [http://de.selfhtml.org/javascript/sprache/index.htm SelfHTML] (//german//) * [http://www.tutorialspoint.com/javascript/index.htm Tutorialspoint] * [http://www.ecma-international.org/ecma-262/5.1/ Official language reference] * [http://ejohn.org/blog/ecmascript-5-strict-mode-json-and-more/ ECMA Strict mode and more] * Variaous Wikipedia articles in German and English * Google ;) Be aware that only the language related features are available not the ones specific for web development. Our scripts should use the so called strict-mode which forbids a few common mistakes. A reasonably good documentation of it can be found here https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Functions_and_function_scope/Strict_mode. **A full reference to the additional !JavaScript elements of our *dimctrl* is available [https://www.fact-project.org/dimctrl here].** The following will contain an example script and some explanations. == Basics == === Include === With the following code you can include code from other scripts. This might, e.g., help to write a little library. Note that the code included as it would be written at this place of the file. {{{#!java include('test3.js'); include("test2.js"); }}} === Output === There are two kinds of output: to the local console (*out*) or as log-message of the script (*print*). {{{#!java console.out("This message will be shown on the local console of dimctrl."); dim.print("This message will appear as log-message in the global log-streams.") }}} === Arguments === Arguments can be passed to the script when the script is started. This can be done from dimctrl's console or when a script is started either through a Dim Command or dimctrl's commandline. Each argument can have a name (e.g. declination=20). In this case it will be accessible by by either $!['declination'] or arg!['declinatioin']. Arguments can also be passed without name. In this case they can be accessed by their index (which refers to all unnamed arguments), e.g. $![2] or arg![2]. {{{#!java // Arguments are accessible as $ and arg (both are exchangable) // Loop over all arguments by property name for (var name in $) { // "Print" a message to the console and the global log-file // (Corresponds, currently, to the batch script ">" command) console.out("Arguments: " + name + "=" + $[name]); } // Loop over all arguments by index for (var i=0; i0: valid names are available, data received // // d.data===undefined: no data received yet // d.data===null: event received, but contains no data // d.data.length>0: event received, contains data console.out("Format: "+d.format); // Dim format string console.out("Counter: "+d.counter); // How many service object have been received so far? console.out("Time: "+d.time); // Which time is attached to the data? console.out("QoS: "+d.qos); // Quality-of-Service parameter console.out("Length: "+d.data.length); // Number of entries in data array console.out("Data: "+d.data); // Print array // Or to plot the whole contents, you can do console.out(JSON.stringify(d)); console.out(JSON.stringify(d.data)); console.out(JSON.stringify(d.obj)); // Loop over all service properties by name for (var name in d.obj) { console.out("obj." + name + "=" + d.obj[name]); } // Loop over all service properties by index for (var i=0; i