Home Scripting Scripting Object Reference

3.1 Scripting Syntax

This chapter will give you an overview about the syntax used in Silverjuke scripts. If you are already familiar with this, the next chapters describe the objects and methods specific to Silverjuke.

Overview

The syntax for Silverjuke scripts follow the rules defined by ECMAScript, 3rd edition. The syntax is very close to JavaScript, C/C++ and to other well-known languages.

If you have ever written a little program or a script in another language, you should have no problems with Silverjuke scripts.

Variables

Variables have no type attached, and any value can be stored in any variable.

a = 1;         // declare a global variable
function var_test()
{
  var b = 2;   // this is a variable local to var_test()
  c = 'str';   // this also declares a global variable
}

var_test();    // call var_test()
print(a);      // will print 1
print(b);      // b is undefined as local to var_test()
print(c);      // will print 'str'

Basic Data Types

Basic data types are boolean, numbers, strings, arrays and objects. Conversion between these types is done as needed.

a = true;              // create a boolean

b = 12.2;              // assign a number to b
c = 'test string';     // assign a string to c
d = "another string";  // assign a string to d

e = [0,1,2];           // create an array with three elements
f = new Array(0,1,2);  // same using the new operator

g = new Object;        // create a new (empty) object
g.prop = 23;           // assign a property to the object

h = new Date;          // create an object of a predefined class
h.getDay()             // call a method (a callable property) of the object

There is no need to worry about deleting variables - this is done automatically by Silverjuke's garbage collection.

Control Structures

You can use the control structures if, switch, for, while and do..while.

if( program.kioskMode ) {
  // we're in kiosk mode, do what to do
} else  {
  // we're not in kiosk mode, do what to do
}

switch( program.viewMode ) {
  case 0: // we're in album mode, do what to do
    break;

  case 1: // we're in cover mode, do what to do
    break;

  default: // handle other modes here
    break;
}

Functions

A function is a block with a (possibly empty) argument list and an optional name. A function may give back a return value.

// declare the function
function my_func_text( a )
{
  print( a ); // call the predefined function print()
}

// call the function
my_func_test( 'Hello!' );

// functions may also be used as properties for objects:
program.launchBrowser( 'http://...' );

// you can also give "anonymous" (unnamed) functions directly as arguments:
program.addMenuEntry( 'bla', function(){alert('Unamed function')} );

Are arguments given by value or by reference? This is quite easy to answer:

Error Handling

If any error occur while your script is executed, an error object is thrown. You may catch these errors using a try..catch block:

try {
  // do what to do here
}
catch(err) {
  // if any error occurs in the try block above, we go here.
}
// here we go if no erros occur

If any error is thrown outside a try..catch block, the script is terminated immediately; in this case - and eg. for syntax errors - Silverjuke logs and error to the console window.

BTW: You can also easily test a function, a macro or a little script by just entering it to the text file and click on "Evaluate".

Now, as you have an idea about the syntax, you may want to have a look at the next chapters which describe the objects and methods specific for Silverjue.


Home Scripting Scripting Object Reference

Search

Latest news from the Forum

RSS+Newsletter