Exercises: Variables

With Variables, you can transfer information from screen to screen and create advanced interactions. Check out these exercises to learn how to use them.

Share information between screens

In this exercise, you’ll create an email address sign-up screen and see that email reflected on a confirmation screen.
Example of sharing information between screens. Email address entered on one screen is reflected on the other

Design the example

  1. Create a prototype with two screens. Go to Screen 1 and design a sign-up form using an Input Text Field F and a Button B.Input text field and a button creating a form
  2. Add a text element to Screen 2 and style it as preferred. You’ll use this text element to show the email address you entered on the previous screen.
  3. Go to the Variables palette and create a new variable by clicking on the ‘+’ button. Name the variable “Email” and leave its default value blank.Email variable pop-up

Create the events

  1. Go back to Screen 1 and select the input text field. Drag it to the “Email” variable in the Variables palette.
    Input dragging to variable
    This creates an On Page Unload + Set Value event, which gives the variable the value you enter in the input text field when you navigate away from the screen.
  2. Select the button below the input text field and drag it to Screen 2 in the Screens palette, creating a link from the button to Screen 2.
  3. Go to Screen 2 and drag the “Email” variable to the text element on the screen.
    Email variable dragged to text element, creating an on page load + set value event
    This creates an On Page Load + Set Value event and gives the text element the variable’s value when the screen first loads.

Click the ‘Play’ button to simulate your prototype. Type in an email address in the sign-up form and click the button to navigate to Screen 2. You’ll see the email you typed in reflected on the text element.

Download this example.

Show or hide conditional content

You can use variables with conditions to determine the relationship between elements on different screens. In this example, you’ll learn how to build a sign-in form that shows more content on another screen depending on what you enter into the form.
Entering information in an input field to see more or less content on another screen

Design the example

  1. Create a prototype with two screens. Build a sign-in form on Screen 1 with an Input Text Field and a Button.
  2. Go to Screen 2 and design it as preferred. Select some elements on the screen and group them using Command / Control + G.
  3. Mark that group as hidden in the Properties palette.Group selected and marked as hidden
  4. Create a new variable named “User” and leave its default value empty.

Create the events

  1. Go back to Screen 1 and select the input text field in the sign-in form. Drag that input text field to the “User” variable in the Variable’s palette, which creates an On Page Unload + Set Value event.Username input text field dragged to variable
  2. Select the button on this screen and drag it to Screen 2 in the Screens palette, which creates a link between the screens.
  3. Go to Screen 2 and double-click on the Canvas to select the base screen.
  4. Look to the Events palette and click ‘Add event’. Build an On Page Load + Show event, showing the group you created earlier. Click ‘OK’ to finish building the event.
  5. Click the ‘Add condition’ text link above the event you just created, which will open the Conditional Expression builder.Hovering over add condition text link
  6. Follow these steps to build the condition:
    • a. Click to the ‘Variables’ tab in the Canvas preview and drag the “User” variable to the open space in the expression.
    • b. Drag an Equals (=) logic function next to the variable.
    • c. You’ll see a new open space appear, where you can type in “Admin”.
    • d. Click ‘OK’ to finish building the condition.

Click the ‘Play’ button to simulate your prototype. Enter “Admin” into the input text field, click the button to go to Screen 2, and you’ll see all the content show up on the screen.

Simulate the prototype again and type some other value into the input text field. Click the button to go to screen 2 and you’ll see fewer elements on the screen this time.

Download this example.

Recurring events

In this exercise, you’ll learn how to use the On Variable Change trigger, which allows you to create automated events, like a countdown timer.

Design the example

  1. Add a Text element and a Button to the Canvas. Give the text element a value of “10” and label the button “Start”.
  2. Create a new variable named “Countdown” and leave its default value blank.

Create the events

  1. Select the “Start” button on the Canvas and create an On Tap + Set Value event. Select the “Countdown” variable as the target of the event and type in “11” as the value to give the variable.Countdown variable has fixed value of 11
  2. Click the ‘+’ button at the top of the palette to add another interaction.
  3. Select an On Variable Change trigger. You’ll see a dropdown appear where you can pick the “Countdown” variable.
  4. Select a Pause action and change the duration to 1000ms (1 second). Click ‘OK’ to finish building the event.An on variable change and pause event
  5. Look to the action you just created in the Events palette and click the ‘+’ button to add another action.Add action button hovered
  6. Choose an On Variable Change with the “Countdown” variable. Pick a Set Value action and tap the ‘Variables’ radio button to find the “Countdown” variable to select.
  7. For the value, click the ‘Calculated’ radio button and the ‘Add expression’ text link, which will open the Value Expression builder.
  8. Follow these steps to build the expression:
    • a. Click to the ‘Variables’ tab in the Canvas preview and drag the “Countdown” variable to the open space in the expression.
    • b. Place a Minus (–) number function next to it.
    • c. You’ll see a new space appear in the expression, where you can type in “1”.
    • d. Click ‘OK’ to finish building the expression and the event.
  9. Click the ‘+’ button to add one more action – On Variable Change + Set Value. Select the text element as the target of the action and click the ‘Calculated’ radio button and the ‘Add expression’ text link.
  10. Drag the “Countdown” variable to the open space in the expression and click ‘OK’ to finish building the event.
  11. Click the ‘add condition’ text link above your On Variable Change events. Drag the “Countdown” variable to the open space in the expression, followed by a Greater or Equals (≥) logic function. Finally, type in “1” into the open space that appears and click ‘OK’.

Here’s how your Events palette should look:

This example works by changing the value of the “Countdown” variable when you click on the “Start” button. This triggers the On Variable Change actions – pausing for one second and then subtracting 1 from the variable. The last action transfers the variable’s value to the text element.

Because the second Set Value event affects the variable itself (subtracting 1), the events trigger all over again until the variable’s value is less than 1.

Download this example