LocalTrack
The LocalTrack feature introduces an innovative approach to development in Storyline, introducing :
- A new logic in trigger programming and
- A new use of variables.
Presentation
LocalTrack interacts exclusively with variables of type Number
.
The feature is based on "operating expressions ", which means that the operations to be executed are specified in a character string and are no longer programmed directly in the triggers.
LocalTrack manipulates the values of numbers as binary expressions: the operating expressions can thus be based on 2 logics: the indexes of the bits and the value of the bits.
Binary concepts
This article is not intended to be a course in binary trading, but for those who are not at ease with the vocabulary, here is a short summary of the terms most commonly used to understand Nuggets.
- A binary expression is a sequence of
0s
and1s
; - Each
0
and1
occupies a space called abit
; - A
bit
can therefore be equal to0
or1
. - A
bit
location is characterised by itsindex
. - Indexes are numbered from
0
and start from the right. - The decimal value of a
bit
is calculated by taking 2 to the power ofindex
, i.e. 2index
.
The interest
The interest of a binary expression lies in its use as an array storing data:
- the data must answer
True/False
,Yes/No
, etc. to a problem or question; - they all belong to the same category within a single binary expression.
For example, you can store all the slides in a scene in Storyline in a binary expression:
- its index in the scene will correspond to the index in the binary expression ;
- when visited, the bit in the expression will swap to
1
.
Warning
In computer systems, the use of a signed bit to define whether a floating-point number is positive or negative imposes a limit of 32 bits. If you use LocalTrack in your projects, always work with indexes between 0 and 31.
With these concepts in mind, let's move on to initialising the functionality in your .STORY
file.
Initialisation and parameters
Variables
LocalTrack always works with binomial variables:
- a variable of type
Text
to state the operations to be performed and - a variable of type
Number
to return the result of the operations if there is a result.
For the purposes of this article, we'll call them Tracking
and Result
.
Trigger
Let's now create the trigger which will execute the processing of the operative expressions passed via the Tracking
variable. This trigger will be created on the Main Slide Master.
Storyline trigger
When 'Tracking' changes
- Execute 'JavaScript'
If 'Tracking' ≠ value '(empty)'
And in the JavaScript Editor :
JavaScript
LocalTrack.parse('Tracking','Result');
Additional informations
LocalTrack.parse
accepts a third Text
typed argument.
This argument defines the suffix to be assigned to additional variables to be created:
- variables must be of type
Text
; - They must be named by combining the suffix and the names of the variables used, either as binomial variables or in operative expressions;
- they systematically return the binary values in the form of a sequence of
0' and
1' of the associated variables; - They are intended to be used with the
%
processor in text fields.
Ex :%Tracking_binary%
,%Result_binary%
,%maVariable_binary%
, etc.
The feature is now ready to be used in a project.
Utilisation
Let's look at an example straight away to understand how to use LocalTrack.
Given a variable myVar
equal to 0
at the initial point.
Storyline trigger
When the user clicks 'My Button 1'
- Set 'Tracking' to value 'myVar+1'
The Tracking
text variable receives an operating expression, the trigger created in the initialisation phase reacts.
Let's try to break down this operation as LocalTrack processes it. In this example, we "add 1
". The result of this operation stores 2
in the myVar
variable.
Why?
Let's return to the explanation of number manipulation given earlier in the section "Principle": expressions can be based on the bit indexes or on the bit values.
Here, the +
indicates that the operation must be based on the indexes. The operation can be interpreted as follows: add to myVar
(which is equal to 0
) a bit equal to 1 in index 1, i.e. 21. The result is: 0+2=2
.
Let's carry out another operation.
Storyline trigger
When the user clicks 'My Button 4'
- Set 'Tracking' to value 'myVar+4'
The operation can be interpreted as follows: add to myVar
(which is equal to 2
now) a bit equal to 1 in index 4, i.e. 24, or 2+16=18
. The binary value of myVar
is indeed 10010
.
The interest
Performing an operation using operand expressions always gives the same result. No matter how many times myVar+1
is run, the result will always return 2
.
Adding 1 in decimal format from Storyline triggers increments the variable by 1 each time the trigger is executed.
Of course, addition is not the only operation that can be performed. Let's take a look at the operations interpreted by LocalTrack.
Supported operations
LocalTrack supports several operational expressions, each of which works in a specific way.
Here is the complete list (N
being equal to 2n
):
Operation | Index | Binary | Exemples |
---|---|---|---|
Addition | +n |
|N |
Toggles the bit at index n to 1 if it is not already equals to 1 .Ex : myVar+4 is equivalent to myVar|16 . |
Subtraction | -n |
~N |
Sets the bit at index n to 0 if it is not already equal to 0 .Ex : myVar-3 is equivalent to myVar~8 . |
Condition | ? |
& |
Executes a condition on the bit at index n and returns its value in the Result variable.Ex : myVar?5 is equivalent to myVar&32 and can be equal to 0 or 2n. |
! |
Returns the number of bits equivalent to 0 or 1 .Ex: If myVar equals 26, its binary value is 11010 .myVar!1 returns 3 and myVar!0 returns 2. |
Now let's see how to use them!
Handling operations
Rules on operating expressions
An operating expression is created by combining a variable name, an operand and a value in a character string. This string will be transmitted to the processing variable.
Ex : myVariable+5
, myVariable|32
, myVariable-5
, myVariable~32
, etc.
The processing of each operative expression performs each operation on the value of the variable and returns the result in the variable.
Multiple operations
Several operations can be entered in a chain in the same operating expression. Operations are performed from left to right.
Ex : myVariable+2+5+7
The operation is equivalent to performing the sum of all the bits : 22+25+27 = 4 + 32 + 128 = 164
The sum of the bits is added to the value of myVariable
and returned to this variable.
Note that myVariable|164
is equivalent.
Hints
The "index" and "binary" operands can be mixed together.
Exemple : myVariable~164+2
Here we subtract several bits to reset the variable, then add the bit to index 2.
Conditional operations
Conditional operations are used to find out the value of one or more bits in a binary expression.
They are performed with the conditional operands ?
to return the bit at the index passed to the right of the operand, and &
to return the bits identical to the binary expression passed to the right of the operand.
Ex : myVariable?5
returns the bit in index 5 of the variable myVariable
The result of this operation is either 0
if the bit contained 0
, or 32
(25) if the bit contained 1
.
Conditional operations can also be performed using the sum of several bits.
Ex : myVariable&164
returns the sum of bits n°2, n°5 and n°7 of the variable myVariable
.
Point of interest
If you mix operational expressions with conditional expressions, put the conditions in the last position. In this way, they will take into account the operative expressions in the expression.
Exemple : myVariable+2&164
Operations with variables
Operative expressions can be created using variable names to the right of the operands.
Ex: myVariable+indexButtonX
, myVariable&progressChapX
, etc.
In this way, declaring a variable at one point in a project and using it in the operative expressions makes development easier and more flexible.
Similarly, it is possible to link several operations with one or more variables in an operative expression.
Storyline triggers
When the timeline starts on 'this slide'
- Set 'Correct' to value '164'
When the user clicks 'Button 1'
- Set 'Tracking' to value 'myVariable+1&Correct'
- // Etc.
When the user clicks 'Button 2'
- Set 'Tracking' to value 'myVariable+2&Correct'
- // Etc.