Chapter 3. Writing and Executing Algorithms in Rocs

Rocs internally uses the QtScript scripting engine, which is a specific JavaScript engine. This means, all algorithms that you implement must use JavaScript. How JavaScript works and how to write JavaScript code is not covered in this handbook, though we explain how to access data structures, data elements and pointers of your data structures from the scripting engine. Since you never use the basic data structure object but one that is provided by the currently used data structure backend, the functionality of the data structure is extended by the corresponding backend and you should have a look at the specialized functionality. Especially, data structure backends use the common terms from their domain (nodes and edges in graphs, leafs and roots in trees, etc.)

It is important to know that changes done by the scripting engine are directly reflected at the properties at the visual graph editor whiteboard. Hence, the scripts actually modify the data structures.

Controlling the Script Execution

Include Files

Your script documents can include other scripts. This can be useful to reduce the size of script documents and improve readability. Using Script DocumentPossible Includes you get a list of script files already shipped with Rocs that could be included. You can include a script file with the following command:

    include_script(string path);            // relative or absolute path to script file

Script Output

During the execution of an algorithm, debug and program output is displayed in the Debug & Script Output. If the scripting engine detects a syntax error in your script, the error is also displayed as debug message. Note that all program messages are also displayed at the debug output (displayed as bold text).

You can control the text that is displayed at the script output by the following functions:

    Console.log(string message);            // displays the message as script output
    Console.debug(string message);          // displays the message as debug output

Control Script Execution

There are different execution modes for your scripts.

You can control the text that is displayed at the script output by the following functions:

  • Run: Execute the script until it finishes.

  • One Step: Execute script until one step ends. A step ends when the script calls the function interrupt():

            interrupt();    // ends a step
  • Debug: Execute script in debug mode. This opens the QtScript debug dialog.

  • Stop: Stop script execution (only available if a script is executing).