Using CpExtra Command Variables

This topic explains how to use CpExtra command variables to set up and execute actions in Captivate HTML5 output.

Before reading this page, please make sure you have familiarized yourself with CpExtra's basic concepts.

How To Create A Command Variable

  1. Identify the command variable you wish to create. Each command variable is tied to only one name, you'll need to know that name of the command variable before you can create it.
  2. On the menu bar, go to Project > Variables... this opens the Variables dialog.
  3. Click Add New
  4. In the Name field, type the variable's name. The variable name is case sensitive. (Note: If you want the command variable to sort to the top of the variable's list, then you can put an underscore in front of its name. _xcmndHide will work exactly the same as xcmndHide)
  5. Click Save. The command variable has successfully been created.

You do not need to give command variables default values, they will be ignored. In fact, if you ever read a Command Variable's value, it will always come back as 0.

Command variables should never be used to save a value. They should only ever be used to perform actions.

What Can Command Variables Do?

All sorts of things.

Currently they break down into the following categories.

Click the links above to see specific instructions on how to use those variables.

How To Use Command Variables

Command variables perform actions based on whatever value you assign to them. Many command variables require multiple items of information in order to operate. These separate items of information are called "Parameters". It is highly recommended you read the help on how to use parameters before starting to use command variables.

There are only two places in Captivate where you can assign a value to a variable. Therefore any place in Captivate where you can change the value of a variable allows you to enact a command variable. These are the following places. 

Fulfilling an Interactive Object's Criteria

Interactive Objects (These are: Buttons, Click Boxes, Text Entry Boxes, some Widgets, or Smart Shapes designated to be used as Buttons) allow you to trigger actions when a certain criteria is met.

These settings are configured under the Actions sub-menu.

For example, for a Button, the success criteria is met when you click the button. If you turn off Infinite Attempts, the button will then have a last attempt criteria, which is met if you click anything other than the button.

You can choose from a list what action should be taken when any of these criterias are met. One of those actions is called Assign.

The Assign action allows you to change a variable's value. When you assign to a command variable a value it can understand, it will then take action.

It is therefore very easy to enact a command variable's action when clicking on a button.

On Slide Enter / Exit

Much like above, you can also choose specific actions that can take place when entering and exiting a slide. This is done in the following way:

  1. Go to the slide you wish to perform the enter / exit action on.
  2. Open the Properties panel.
  3. Make sure nothing is selected on slide.
  4. Go to the Actions submenu.
  5. There you will see an On Enter and On Exit drop down menu.

From those drop down menus you can also pick the Assign action to change a command variable's value.

On Answering a Quiz Question / Drag and Drop Interaction

You can also take certain actions on correctly or incorrectly answering a quiz question of drag and drop question.

Quiz Questions

  1. Go to a quiz slide.
  2. Open the Quiz panel.
  3. Scroll down to the Actions section.
  4. There you will see the On Success and Last Attempt drop down menus.

Once again, from here you can pick the Assign action.

Drag and Drop Interactions

  1. Go to a slide with a drag and drop interaction.
  2. Open the Drag and Drop panel
  3. There you will see the On Success and On Failure drop down menus.

The Assign action is available here also.

In an Advanced Action

If you are looking to do anything more than a simple interaction, then you're probably going to want to call a succession of actions, rather than just one.

This is achieved by using Advanced Actions. They are created by going to Project > Advanced Actions.

From there you can use the Assign action (or potentially even use the Expression action) to send a value to a command variable.

For more information about using Advanced Actions, check out our course about them here.

In JavaScript

You can also change Captivate Variables whenever you execute JavasScript in the Captivate course. This is commonly done through the Execute JavaScript action, which is generally available anywhere you can choose the Assign action.

To change a command variable (or any system/user variable) in Javascript, all you have to do is write out the name of the variable, and then assign it a string.

For example, you want to hide a caption on slide called MyCaption. That can be done by assigning the string MyCaption to xcmndHide.

In Javascript you'd write that code like so:

xcmndHide = "MyCaption";

The quotation marks are essential. They tell JavaScript that anything between those quotation marks is not code, but rather just words (in programmer talk, that's called a string).

IF YOU LIKE WHAT YOU'VE READ ABOVE, THERE'S PLENTY MORE!

Join more than 2500 other Adobe Captivate users just like yourself and receive regular troubleshooting tips, illustrated tutorials, technical information, and creative solutions to real-world e-learning development issues. (See an example here.) Click the button below to join our community.  It's completely FREE!