Use Script Objects

As a story developer, you can use script objects to encapsulate a set of functions that can be reused in scripting.

About Script Objects

Script objects act as containers of script functions that aren’t specific to an event and can be used directly. They can thus save you from duplicating codes and make maintenance of stories easier.

Once you've added a script object, you can add script functions and write scripts for them. Each function have access to other objects in the story, such as widgets, global variables, and popups.

A script function has the following elements:
  • Name

  • Return type

  • Arguments

Later when writing scripts, you can access a script object by its name.

Create a Script Object with Script Function

Procedure

  1. In the Scripting area of the Outline panel, choose Start of the navigation path Next navigation step End of the navigation path Script Objects.

    The new script object is displayed under Script Objects, and a Script Function panel opens.

  2. In the Properties section, configure the following settings for the script function:

    Element

    Description

    ID

    ID is mandatory and it validates according to the same rules as for global variables. Name can't be empty or a reserved keyword and should begin with a letter.

    Description

    (Optional) A brief description of the function.

    Return Type

    Can be void, string, boolean, integer, or number. By default, the return type is void.

    Besides the primitive types described above, you can also select a wide variety of non-primitive types such as Button, Category, Chart, DataSource, Table, and UrlType.

    Set as Array

    Only activated if the return type is not void.

  3. In the Arguments section select + Add Argument to create a new argument for the function.
  4. In the Argument panel, edit ID and type of the argument.

    If the argument should represent a list of this type, set it to array.

  5. Choose Done to close the Argument panel and return to Script Function.
  6. Optional: You can reorder the arguments by dragging and dropping them inside the panel.

    This changes the order of the arguments in the defined function.

  7. In the Outline panel select (Edit Scripts) right next to the script object to write scripts for the script function.

Results

You've created a script object containing a script function, which can be reused in any other scripts.

You can add multiple script functions to the script object by selecting (More)Start of the navigation path Next navigation step End of the navigation path Add Script Function next to it in the Outline panel.

To call a function in the script object, for example, function1 in ScriptObject_1, enter the following:
ScriptObject_1.function1();

Modify And Delete Script Objects and Script Functions

To change the name, description, arguments and return type of a script function, select it in the Scripting area of the Outline panel. The panel opens where you can directly update your changes. After you've changed the elements, select Done to close the panel.

To edit an argument, in the Arguments section of the Script Function panel, select (Edit) when hovering over it. To remove an argument, select (Remove) next to it.

To delete a script object or script function, select (More) next to it and then Delete.