Advanced Puzzles

Use these puzzles to implement advanced features in your apps, such as networking, interation with JavaScript code, data conversion, state saving/restoring and more.

Contents

Puzzles Reference

exec script

This puzzle executes the specified javascript code. The puzzle uses Ace Editor for displaying and editing the content. See the relevant keyboard shortcuts here: Default Keyboard Shortcuts.

You can use the following built-in variables:

Specifics of using built-ins regarding to "Init" and other tabs

call external function

Executes a function specified in the JavaScript code of the application. Optionally passes parameters to be used as function arguments.

In order to add a function to JavaScript code, open the application .js file (for example, my_awesome_app.js located in verge3d/applications/my_awesome_app) with any text editor. Search for "prepareExternalInterface" and add your function inside that declaration (between the curly brackets), so that it looks like this:

function prepareExternalInterface(app) { app.ExternalInterface.myJSFunction = function(numericArg, textArg) { alert('Got some params from Puzzles: ' + numericArg + ' and ' + textArg); } }

load data

Attempts to load data from a specified location. The puzzles in the "once ready do" slot are interpreted regardless of whether the attempt was a success. The retrieved data can be accessed via the loaded data puzzle.

send data

Attempts to send a specified data to a remote location using an asynchronous POST HTTP request. The puzzles in the "once ready do" slot are interpreted regardless of whether the attempt was a success. If there is any response data, it can be accessed via the loaded data puzzle.

loaded data

Returns data retrieved by the load data or send data puzzles.

read JSON

Interprets text (or Data URI) as JavaScript Object Notation data which is returned in a dictionary.

read CSV

Interprets text (or Data URI) as comma-separated values. Returns a list of table rows, with each row represented as a list of values. The delimiter can be selected with the drop-down to correspond a CSV file's export settings. "From row" value denotes how many rows will be skipped starting from the top.

Table rows and values are accessed by their numeric indices starting from 0.

save state

Saves the state of specified objects and/or the values of variables specified by their names. The objects are cloned and stored in memory. The values of the variables are retrieved and stored in memory for each specified variable name.

If this puzzle is called several times, the states are saved in sequence so that it is possible to return to any previous state with the undo state puzzle.

undo state

Restores the state of objects and/or variables saved with the save state puzzle.

If this puzzle is called several times, the states are restored from the saved sequence (if any) which makes it possible to return to any previously saved state from the stack. Sometimes you need to catch the situation when there is no saved state present in the undo history, e.g to make changes in the UI. For that, use the state counter variable:

all variable names

Returns a list with the names of all variables used in Puzzles.

variable value by name

Returns the value of a variable specified by its name. This puzzle works similarly to the standard variable value puzzle, yet does not require to select a variable from the predefined dropdown menu.

JavaScript object

Returns a given JavaScript object.

You can get the following JavaScript objects with this puzzle:

window
Return the top-level window object as dictionary value.
arguments
Returns the list of arguments of the currently executed function. Can be used to get arguments of Puzzles procedures or additional arguments passed to internal Puzzles callbacks (see below).
this
JavaScript this value.

The arguments option can be used to retrieve additional puzzles options. For example, when using when clicked puzzle, you can get the internal JavaScript event which triggers the puzzle logic using the first argument of the callback executed behind the do slot. In the example below we use this event to get X and Y coordinates of the mouse pointer:

The following puzzles support advanced options:

wait promise

Wait for the promise to be resolved or rejected and return its value (or rejection reason) in the promise value puzzle.

This puzzle may be required to get value of the export to gltf and generate normal map puzzles. Being async puzzles by their nature, these puzzle do not return resolved values immediately. Instead, they return promise values which are resolved in the puzzles they are used as inputs. In some rare cases, however, this resolving does not happen. In these cases you should use wait promise to resolve promise values.

promise value

Resolved promise value (in case of resolved promise) or error string (in case of rejected promise).

connector

This puzzle facilitates connecting other puzzles with each other, to make it more convenient to move, delete and use them in other puzzles. The most notable application is to join load sound or load video puzzles into a single group to organize preloading of media resources in your application.

Having Troubles with Puzzles?

Seek help on the forums!