This page has been translated automatically.
Programming
Fundamentials
Setting Up Development Environment
UnigineScript
High-Level Systems
C++
C#
UUSL (Unified UNIGINE Shader Language)
File Formats
Rebuilding the Engine and Tools
GUI
Double Precision Coordinates
API
Bounds-Related Classes
Containers
Controls-Related Classes
Core Library
Engine-Related Classes
GUI-Related Classes
Node-Related Classes
Pathfinding-Related Classes
Physics-Related Classes
Plugins-Related Classes
Rendering-Related Classes
Utility Classes
Warning! This version of documentation is OUTDATED, as it describes an older SDK version! Please switch to the documentation for the latest SDK version.
Warning! This version of documentation describes an old SDK version which is no longer supported! Please upgrade to the latest SDK version.

Browser Functions

The following functions are defined for the global object Browser that can be used to customize the logic of the launcher. These functions are available for both JavaScript and UnigineScript.

Notice
  • When using a function on the UnigineScript side, add the browser. prefix to it. For example: browser.getWidth();.
  • When using a function on the JavaScript side, add the Browser. prefix to it. For example: Browser.call("run");. Note that the prefix must start with the capital B.

void call (string name)

Calls a function without arguments. This function should be used to call functions defined on the UnigineScript side from the JavaScript code.

Arguments

  • string name - A name of a function to call.

void call (string name, Variable a0)

Calls a function with 1 argument. This function should be used to call functions defined on the UnigineScript side from the JavaScript code.

Arguments

  • string name - A name of a function to call.
  • Variable a0 - The first function argument.

void call (string name, Variable a0, Variable a1)

Calls a function with 2 arguments. This function should be used to call functions defined on the UnigineScript side from the JavaScript code.

Arguments

  • string name - A name of a function to call.
  • Variable a0 - The 1st function argument.
  • Variable a1 - The 2nd function argument.

void call (string name, Variable a0, Variable a1, Variable a2)

Calls a function with 3 arguments. This function should be used to call functions defined on the UnigineScript side from the JavaScript code.

Arguments

  • string name - A name of a function to call.
  • Variable a0 - The 1st function argument.
  • Variable a1 - The 2nd function argument.
  • Variable a2 - The 3rd function argument.

void call (string name, Variable a0, Variable a1, Variable a2, Variable a3)

Calls a function with 4 arguments. This function should be used to call functions defined on the UnigineScript side from the JavaScript code.

Arguments

  • string name - A name of a function to call.
  • Variable a0 - The 1st function argument.
  • Variable a1 - The 2nd function argument.
  • Variable a2 - The 3rd function argument.
  • Variable a3 - The 4th function argument.

int getWidth ()

Returns the screen width.

Return value

Width of the screen.

Examples

Source code
Browser.getWidth();

int getHeight ()

Returns the screen height.

Return value

Height of the screen.

Examples

Source code
Browser.getHeight();

string getData ()

Returns a path to the local settings on Windows. On the other platforms, it returns a path to a directory where persistent application data can be stored. This is an application-specific directory.

Return value

A path.

string getGenericData ()

Returns a path to a directory where persistent data shared across applications can be stored. This is a generic value.

Return value

A path.

string getHome ()

Returns a path the user's home directory.

Return value

A path to the home directory.

string getTemp ()

Returns a path to a directory where temporary files are stored. The returned value might be application-specific, shared among other applications for the current user, or system-wide.

Return value

A path to the temp directory.

string getDesktop ()

Returns a path to the user's desktop directory.

Return value

A path to the desktop directory.

string getDownload ()

Returns a path to a directory for user's downloaded files.

Return value

A path to the directory with downloaded files.

string getDocuments ()

Returns a path to a directory that contains user document files.

Return value

A path to the directory with documents.

string getDirectory ()

Returns the current directory.

Return value

Current directory.

string getPlatform ()

Returns the name of the operating system.

Return value

Name of the operating system.

string getVersion ()

Returns the version of the operating system (only for Windows). The version can take the following values:
  • 50 - Windows 2000
  • 51 - Windows XP
  • 52 - Windows Server 2003 (Windows XP sp2)
  • 60 - Windows Vista
  • 61 - Windows 7
  • 62 - Widows 8
  • 63 - Windows 8.1

Return value

Version of the operating system.

string getArch ()

Returns the operating system bit rate.

Return value

Bit rate.

int getNumArgs ()

Returns the number of command-line options that are used to launch the application.

Return value

The number of the command-line options.

string getArg (int num)

Returns the value of the command-line option by its number.

Arguments

  • int num - Number of the target command-line option.

Return value

The option value.

int isArgument (string name)

Returns the value indicating if the option is specified in the arguments section of the launcher.xml file.

Arguments

  • string name - Name of the option.

Return value

1 if the option is specified; otherwise 0.

Examples

The following example checks existence of the magic option in the configuration file launcher.xml:

Source code
if (Browser.isArgument('magic')) {
	alert('The magic option exists.');
}

string getArgument (string name)

Returns the value of the option specified in the arguments section of the launcher.xml file.

Arguments

  • string name - Name of the option.

Return value

Option value.

int runProcess (string command)

Starts the command in a new process, waits for its finish and returns the exit code.

Arguments

  • string command - The command string to run.

Return value

The process exit code. If the process isn't started successfully, -1 will be returned.

Examples

If you run the application via the launcher by using this function, the launcher becomes unavailable until the application shuts down:

Source code(UnigineScript)
browser.runProcess("main_x86.exe -console_command \"config_readonly 1 && world_load \"\"\"unigine_project/unigine_project\"\"\"\"");
Notice
The \ symbols are used here for escaping quotes for UnigineScript. The additional quotes are used for escaping quotes for Qt (as the UnigineScript functions of the Browser object call the corresponding Qt functions).

int runProcess (string working_dir, string command)

Starts the command in a new process in the specified working directory, waits for its finish and returns the exit code. The output of the running process is forwarded to the main process.

Arguments

  • string working_dir - The working directory.
  • string command - The command string to run.

Return value

The process exit code. If the process isn't started successfully, -1 will be returned.

Examples

The following example is the same as for the runProcess() function defined above, except the fact that its first argument specifies the working directory:

Source code(UnigineScript)
browser.runProcess("D:\\my_project\\","main_x86.exe -console_command \"config_readonly 1 && world_load \"\"\"unigine_project/unigine_project\"\"\"\"");
Notice
The \ symbols are used here for escaping quotes for UnigineScript. The additional quotes are used for escaping quotes for Qt (as the UnigineScript functions of the Browser object call the corresponding Qt functions).

int startDetached (string program, string arguments[])

Starts the program with the specified arguments in a new process and detaches from it. If the calling process exits, the detached process will continue to run unaffected. The new process is started in the working directory which is inherited from the calling process.

Arguments

  • string program - A path to a program to run.
  • string arguments[] - A list of arguments.

Return value

1 if the program is started successfully; otherwise, 0.

Examples

If you run the application via the launcher by using this function, the launcher will be still available:

Source code(UnigineScript)
browser.runProcess("main_x86.exe", ("-console_command \"config_readonly 1 && world_load \"\"\"unigine_project/unigine_project\"\"\"\""));
Notice
The \ symbols are used here for escaping quotes for UnigineScript. The additional quotes are used for escaping quotes for Qt (as the UnigineScript functions of the Browser object call the corresponding Qt functions).

int startDetached (string working_dir, string program, string arguments[])

Starts the program with the specified arguments in a new process in the specified working directory and detaches from it. If the calling process exits, the detached process will continue to run unaffected.

Arguments

  • string working_dir - The working directory.
  • string program - A path to a program to run.
  • string arguments[] - A list of arguments.

Return value

1 if the program is started successfully; otherwise, 0.

Examples

The following example is the same as for the startDetached() function defined above, except the fact that its first argument specifies the working directory:

Source code(UnigineScript)
browser.runProcess("D:\\my_project\\","main_x86.exe", ("-console_command \"config_readonly 1 && world_load \"\"\"unigine_project/unigine_project\"\"\"\""));
Notice
The \ symbols are used here for escaping quotes for UnigineScript. The additional quotes are used for escaping quotes for Qt (as the UnigineScript functions of the Browser object call the corresponding Qt functions).

void getSystemEnvironment (string variables[])

Returns the environment variables with its values used by the calling process and saves them to the array of strings passed as an argument.

Arguments

  • string variables[] - A map: an environment variable and its value.

int runInformation (string title, string str)

Shows the information dialog box.

Arguments

  • string title - Title of the dialog box.
  • string str - Message text.

Return value

1 if the OK button is clicked; otherwise 0.

Examples

The following example shows the dialog box with the message:

Source code
Browser.runInformation('Message','Hello World!');

int runQuestion (string title, string str)

Shows the question dialog box.

Arguments

  • string title - Title of the dialog box.
  • string str - Question.

Return value

1 if the OK button is clicked; otherwise 0.

int runWarning (string title, string str)

Shows the warning dialog box.

Arguments

  • string title - Title of the dialog box.
  • string str - Warning text.

Return value

1 if the OK button is clicked; otherwise 0.

string runOpenFile (string title, string str, string filter)

Shows the open file dialog box.

Arguments

  • string title - Title of the dialog box.
  • string str - Path to the target folder.
  • string filter - File filter.

Return value

Returns the selected file name. If the Cancel button is pressed, returns NULL.

Examples

The following example shows the Open file dialog box, where files in the my_project/data/launcher folder are filtered by using the*.png extension:

Source code
Browser.runOpenFile('Open file','my_project/data/launcher','*.png');

string runSaveFile (string title, string str, string filter)

Shows the save file dialog box.

Arguments

  • string title - Title of the dialog box.
  • string str - Path to the target folder.
  • string filter - File filter.

Return value

Returns the selected file name. If the Cancel button is pressed, returns NULL.

string runDirectory (string title, string str, string filter)

Shows the file dialog box.

Arguments

  • string title - Title of the dialog box.
  • string str - Path to the target folder.
  • string filter - File filter.

Return value

Returns the selected directory.

int writeFile (string name, string str)

Writes data to the file.

Arguments

  • string name - Path to the file.
  • string str - Data to write.

Return value

1 if the data is written successfully; otherwise 0.

string readFile (string name)

Reads data from the file.

Arguments

  • string name - Path to the file.

Return value

Data.

string getDirectories (string path)

Returns the list of directories stored at the specified path.

Arguments

  • string path - Path to the target directory.

Return value

Comma-separated names of the directories.

string getFiles (string path)

Returns the list of files stored at the specified path.

Arguments

  • string path - Path to the target directory.

Return value

Comma-separated names of the files.

Examples

Source code
alert(Browser.getFiles('my_project/data/launcher'));
The result is the following:
Output
icon.png,interface.html,launcher.xml,project.css,project.js,style.css,translations.js,UIMess.js

long getAvailableSpace (string path)

Returns the size (in bytes) of the space available for the current user in the volume on which the specified directory or file is located. In general, this function is used to get the size of the free space on the disk.

Arguments

  • string path - A path to a directory or file.

Return value

The available space.
Last update: 2017-07-03
Build: ()