RIATest Documentation Copyright © RIATest.com

Functions

Functions are typically used to create reusable blocks of script.

The syntax for function declaration is the following:

function functionName([parameter-name-1, parameter-name-2, ...])
{
  // function code goes here
}

Once the function is declared it can be called from your script exactly the same way built-in Global functions are called, e.g.:

myFunc("123")

You can return a value from function using return statement, e.g.

function testFunc()
{
  return 123;
}

Note that the function must be declared before it can be called, e.g. the following is not correct:

funcA("123");

function funcA(param)
{
}

This does not prevent from having two functions call each other. For example the following code is correct:

function funcA(param)
{
  if (param>0) return funcB(param-1);
  else return 0;
}

function funcB(param)
{
  if (param>0) return funcA(param-1);
  else return 0;
}

funcA(10);