---
title: "Triggers and variables"
description: "Make slides react - events, actions and conditions, variables for text, numbers and true/false, and where triggers live."
canonical_url: "https://docs.ols.yonn.online/en/interact/triggers-and-variables"
---
# Triggers and variables

> Make slides react - events, actions and conditions, variables for text, numbers and true/false, and where triggers live.

A **trigger** is a small rule that makes your course react: **when** something happens, **do** something. Example: when someone clicks the "Next" button, go to the next slide. You can add a condition (**if** the score is at least 8) and something to do **otherwise**. With triggers you build buttons, pop-ups, branching paths and little games, without writing any code.

A **variable** is a named box that remembers a value while someone works through the course, for example their points, their name or whether a chapter is done.

You work with these parts:

- **Triggers tab**: the list of all triggers of the slide, its layers and the whole course.
- **Trigger window**: where you set the action, the event and optional conditions.
- **Variables window**: where you create and manage your variables.
- **Built-in variables**: values the player fills in by itself, such as the score or the learner's name.

<ui-path path="Properties panel > Triggers" icon="i-lucide-zap">



</ui-path>

## Set up in 4 steps

<procedure>

### Open the Triggers tab

In the properties panel on the right, click the lightning icon. That is the **Triggers** tab. It lists every trigger of the current slide. If you selected an object, you can also right-click it and choose **Add trigger**.

### Click Trigger

Click the orange **Trigger** button at the top of the panel. The window **New trigger** opens. Under **Quick start** you can pick a ready-made template (for example **Button shows layer**), and all fields are filled in for you. More templates: [Trigger recipes](https://docs.ols.yonn.online/en/interact/trigger-recipes).

### Choose the action and the event

Under **1 Action**, choose what should happen, for example **Show layer**. Under **2 Event**, choose when it happens (**When**, for example **User clicks**) and on which **Object**. Below every choice you see a short explanation with an example.

### Check the sentence and save

At the top of the window, the trigger reads as a sentence, for example "Jump to the next slide when the user clicks Tile Networks". If it says what you want, click **Add trigger**.

</procedure>

![The Triggers tab of the sample slide Course menu: the slide on the left, the list of slide triggers with on/off switches on the right](https://docs.ols.yonn.online/screenshots/en/triggers-and-variables-panel.png)

<hint-box kind="tip" title="Try it right away">

Press <key-combo keys="F12">



</key-combo>

 to play the current slide in the preview and click your button. Triggers work in the preview just like in the published course.

</hint-box>

## The Triggers tab

The tab groups triggers by where they are stored: **Slide triggers**, one group per layer (**Layer triggers**) and **Project triggers**. Inside a group, triggers are sorted by the object they belong to.

<table>
<thead>
  <tr>
    <th>
      Element
    </th>
    
    <th>
      What it does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Trigger
      </strong>
      
       (orange button)
    </td>
    
    <td>
      Opens <strong>
        New trigger
      </strong>
      
       for the current slide or layer.
    </td>
  </tr>
  
  <tr>
    <td>
      Filter icon
    </td>
    
    <td>
      <strong>
        Show only triggers of the selected objects
      </strong>
      
      . Handy on busy slides. <strong>
        Show all triggers again
      </strong>
      
       clears the filter.
    </td>
  </tr>
  
  <tr>
    <td>
      Copy and paste icons
    </td>
    
    <td>
      <strong>
        Copy selected triggers
      </strong>
      
       and paste them into another slide or layer (<strong>
        Paste triggers
      </strong>
      
      ).
    </td>
  </tr>
  
  <tr>
    <td>
      Trash icon
    </td>
    
    <td>
      <strong>
        Delete selected triggers
      </strong>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      Plus in a group header
    </td>
    
    <td>
      Adds a trigger to exactly that group, for example to the project triggers.
    </td>
  </tr>
  
  <tr>
    <td>
      Switch in front of a trigger
    </td>
    
    <td>
      Turns the trigger off without deleting it (<strong>
        Turn trigger off (it is kept)
      </strong>
      
      ). Useful for testing.
    </td>
  </tr>
  
  <tr>
    <td>
      Small heading above a trigger
    </td>
    
    <td>
      Your own <strong>
        Label
      </strong>
      
      , if you gave one.
    </td>
  </tr>
  
  <tr>
    <td>
      Click on a trigger
    </td>
    
    <td>
      Selects it, for example to copy or delete it. A double-click opens <strong>
        Edit trigger
      </strong>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      Right-click or the small buttons on a trigger
    </td>
    
    <td>
      <strong>
        Edit trigger
      </strong>
      
      , <strong>
        Duplicate trigger
      </strong>
      
      , <strong>
        Delete trigger
      </strong>
      
      .
    </td>
  </tr>
</tbody>
</table>

## The trigger window

![The New trigger window with Quick start, Action, Event, Conditions and Advanced](https://docs.ols.yonn.online/screenshots/en/triggers-and-variables-editor.png)

<table>
<thead>
  <tr>
    <th>
      Element
    </th>
    
    <th>
      What it does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Sentence at the top
    </td>
    
    <td>
      Shows the whole trigger in plain words, so you can check it at a glance.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Quick start
      </strong>
    </td>
    
    <td>
      Six templates that fill in everything: <strong>
        Button shows layer
      </strong>
      
      , <strong>
        Go to the next slide
      </strong>
      
      , <strong>
        Change state on click
      </strong>
      
      , <strong>
        Count points (variable +1)
      </strong>
      
      , <strong>
        Close layer
      </strong>
      
      , <strong>
        Skip slide if variable is true
      </strong>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        1 Action
      </strong>
    </td>
    
    <td>
      What happens. Depending on the action, more fields appear, for example <strong>
        Layer
      </strong>
      
      , <strong>
        Slide
      </strong>
      
       or <strong>
        Variable
      </strong>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        2 Event
      </strong>
    </td>
    
    <td>
      <strong>
        When
      </strong>
      
       it happens, and for which <strong>
        Object
      </strong>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        3 Conditions
      </strong>
    </td>
    
    <td>
      Optional. The action only runs if the conditions are met. <strong>
        Condition
      </strong>
      
       adds one. Without conditions, the action always runs.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Advanced: Else action
      </strong>
    </td>
    
    <td>
      Something to do when the conditions are not met, for example show a "Wrong" layer instead of "Correct". Add a condition first.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Advanced: Label
      </strong>
    </td>
    
    <td>
      Your own name for the trigger list, for example "Navigation". Helps when a slide has many triggers.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Advanced: Save in
      </strong>
    </td>
    
    <td>
      <strong>
        Slide
      </strong>
      
       (only here), <strong>
        Layer
      </strong>
      
       (only while that layer is visible) or <strong>
        Project
      </strong>
      
       (on every slide).
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Active
      </strong>
    </td>
    
    <td>
      Off: the trigger is saved but does nothing.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Add trigger
      </strong>
      
       / <strong>
        Save
      </strong>
    </td>
    
    <td>
      Saves the trigger. <strong>
        Cancel
      </strong>
      
       closes the window without changes.
    </td>
  </tr>
</tbody>
</table>

## Actions

An action is what the trigger does. In the window they are sorted into groups:

<table>
<thead>
  <tr>
    <th>
      Group
    </th>
    
    <th>
      Actions
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      General
    </td>
    
    <td>
      Change state, Show layer, Hide layer, Show object, Hide object, Toggle visibility, Set focus, Play emphasis, Adjust variable, Start motion path
    </td>
  </tr>
  
  <tr>
    <td>
      Navigation
    </td>
    
    <td>
      Next slide, Previous slide, Jump to slide, Jump to scene, Slide as lightbox, Close lightbox
    </td>
  </tr>
  
  <tr>
    <td>
      Media
    </td>
    
    <td>
      Play media, Pause media, Stop media, Pause timeline, Resume timeline, Restart timeline, Jump on timeline
    </td>
  </tr>
  
  <tr>
    <td>
      Background audio
    </td>
    
    <td>
      Play background audio, Pause background audio, Stop background audio, Set background audio
    </td>
  </tr>
  
  <tr>
    <td>
      Project / results
    </td>
    
    <td>
      Submit interaction, Submit results, Review results, Reset results, Retry quiz, Print results, Exit course, Restart course, Complete course
    </td>
  </tr>
  
  <tr>
    <td>
      More
    </td>
    
    <td>
      Open URL / file, Send email, Execute JavaScript
    </td>
  </tr>
</tbody>
</table>

A **layer** is an extra level on top of a slide, for example a pop-up or a feedback message. A **lightbox** opens another slide as a window on top of the current one.

## Events

An event is the moment the trigger starts.

<table>
<thead>
  <tr>
    <th>
      Group
    </th>
    
    <th>
      Events
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      Mouse
    </td>
    
    <td>
      User clicks, User double-clicks, User right-clicks, Mouse hovers over, Mouse enters, Mouse leaves
    </td>
  </tr>
  
  <tr>
    <td>
      Timeline
    </td>
    
    <td>
      Timeline starts, Timeline ends, Timeline reaches (a point in time or a cue point)
    </td>
  </tr>
  
  <tr>
    <td>
      Objects and variables
    </td>
    
    <td>
      Media completes, State changes, Variable changes, Focus lost, Animation completes
    </td>
  </tr>
  
  <tr>
    <td>
      Drag and drop
    </td>
    
    <td>
      Object dropped on, Object dragged over
    </td>
  </tr>
  
  <tr>
    <td>
      Keyboard and gestures
    </td>
    
    <td>
      Key pressed, User swipes
    </td>
  </tr>
  
  <tr>
    <td>
      Motion
    </td>
    
    <td>
      Object intersects, Intersection ends, Object enters the slide, Object leaves the slide
    </td>
  </tr>
</tbody>
</table>

"Timeline starts" fires as soon as a slide or layer opens. Use it for things that should happen by themselves.

## Conditions

<table>
<thead>
  <tr>
    <th>
      Condition
    </th>
    
    <th>
      What it checks
    </th>
    
    <th>
      Example
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Variable
      </strong>
    </td>
    
    <td>
      The value of a variable: equals, does not equal, is less than, is less than or equal to, is greater than, is greater than or equal to, contains, does not contain, is empty, is not empty
    </td>
    
    <td>
      "Points" is greater than or equal to 8
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Object state
      </strong>
    </td>
    
    <td>
      Whether an object is (or is not) in a state
    </td>
    
    <td>
      The checkbox is "Selected"
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Intersection
      </strong>
    </td>
    
    <td>
      Whether two objects overlap
    </td>
    
    <td>
      The puzzle piece lies on the field
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Window width
      </strong>
    </td>
    
    <td>
      How wide the learner's player window is, with presets for iPhone, iPad, laptop and large screens
    </td>
    
    <td>
      Narrower than 600 px: show a simpler layer
    </td>
  </tr>
</tbody>
</table>

Several conditions are combined with **AND** (all must be true) or **OR** (one is enough).

## Variables

Open <ui-path path="View > Variables">



</ui-path>

 to manage your variables. You can also create a new one right inside the trigger window: open the variable list and choose **New variable**.

<table>
<thead>
  <tr>
    <th>
      Element
    </th>
    
    <th>
      What it does
    </th>
  </tr>
</thead>

<tbody>
  <tr>
    <td>
      <strong>
        Templates
      </strong>
    </td>
    
    <td>
      Ready-made variables: <strong>
        Count points
      </strong>
      
      , <strong>
        Save name
      </strong>
      
      , <strong>
        Chapter done
      </strong>
      
      , <strong>
        Count attempts
      </strong>
      
      .
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        New variable
      </strong>
    </td>
    
    <td>
      Creates an empty variable.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Name
      </strong>
    </td>
    
    <td>
      Letters, digits and <code>
        _
      </code>
      
      , no spaces, not starting with a digit.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Type
      </strong>
    </td>
    
    <td>
      <strong>
        Number
      </strong>
      
       (points, attempts), <strong>
        Text
      </strong>
      
       (a name, an answer) or <strong>
        True/false
      </strong>
      
       (like a switch: chapter done or not).
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Initial value
      </strong>
    </td>
    
    <td>
      The value at the start of the course.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Description
      </strong>
    </td>
    
    <td>
      A note for you: what is the variable for?
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Used
      </strong>
    </td>
    
    <td>
      How often the variable is used in the course.
    </td>
  </tr>
  
  <tr>
    <td>
      <strong>
        Built-in variables
      </strong>
    </td>
    
    <td>
      Read-only values from the player (see below).
    </td>
  </tr>
</tbody>
</table>

To change a variable while the course runs, use the action **Adjust variable**. It can **Assign (=)**, **Add (+)**, **Subtract (-)**, **Multiply (*)**, **Divide (/)**, **Modulo (%)**, **Toggle (true/false)**, pick a **Random number** or **Append (text)**.

To show a variable in a text box, write its name between percent signs: `%Name%`. Example: "Well done, %Name%!"

### Built-in variables

The player fills these values by itself. You can show them in texts and use them in conditions, but you cannot change them. Examples: `Project.SlideNumber`, `Project.TotalSlides`, `Project.ProgressPercent`, `Slide.Title`, `Results.ScorePercent`, `Results.Passed`, `Learner.Name` and `Date.Today`. In the variable list of the trigger window you find all of them under **Built-in (read-only)**.

<hint-box kind="tip" title="Learner name from Moodle">

`%Learner.Name%` shows the name Moodle reports, for example "Hello %Learner.Name%, you scored %Results.ScorePercent% percent."

</hint-box>

## Project triggers

Project triggers apply on every slide. Example from the sample course: when the H key is pressed, jump to the "Course menu" slide. Create one with the plus next to **Project triggers**, or choose **Project** under **Advanced: Save in**.

## JavaScript triggers

The action **Execute JavaScript** runs your own code. You only need it for very special cases.

<hint-box kind="warning" title="Off by default, on only by you">

JavaScript only runs when **Allow JavaScript** is on in <ui-path path="View > Course">



</ui-path>

, and only in the published package, never in the preview. After every import the switch is off again. An AI can never switch it on.

</hint-box>

## If something doesn't work

- **Nothing happens on click**: check the switch in front of the trigger (it must be on) and the **Object** under **Event**. Is the trigger stored on the right layer?
- **The trigger fires on the wrong slide**: under **Advanced: Save in**, check whether it is a slide, layer or project trigger.
- **The condition never matches**: open the preview with <key-combo keys="F12">



</key-combo>

 and click **Variables**. There you watch every value change live.
- **The else action can't be switched on**: it needs at least one condition first.
- **JavaScript does nothing**: it never runs in the preview. Publish the course and turn on **Allow JavaScript**.


## Sitemap

See the full [sitemap](https://docs.ols.yonn.online/sitemap.md) for all pages.
