Persisting Data with CpExtra

This topic explains how to use CpExtra persistence variables to store data for use later in the same project, or by different projects running on the same device.

Browser Storage Variables

All browsers that are supported by Captivate have a feature called Web Storage. Web Storage allows web pages to save variables inside the browser which can then be read by that page later, or by any other page in the same domain.

A domain is the initial part of the web address. So a Captivate course on www.google.com would not be able to share Web Storage variables with www.adobe.com.

Web Storage is divided into two types: Local Storage and Session Storage.

Local Storage variables are saved into the browser and are basically stay there forever. They can only be erased through targeted JavaScript, or by clearing the browser cache.

Session Storage variables on the other hand are only saved while the browser tab is open. The variables are also not shared with other tabs like Local Storage variables are. As soon as the tab is closed, the variables are deleted.

Both types of storage are useful in different circumstances.

To learn more about local and session storage, see this article.

Designating Storage Variables in CpExtra

CpExtra allows you to create an unlimited number of local and session storage variables.

To specify that a variable's value should be saved into Local Storage, put ls_ (l for Local, s for Storage) in front of its name. This is not case sensitive. The following variables would all be saved into local storage:

  • ls_MyVar
  • LS_YourVar
  • _LS_Hello_World (you can put an underscore in front of its name to make it sort ot the top of the variables list)

On the other hand, if you would rather a variable be saved into Session Storage, put ss_ (s for Session, s for Storage) in front of its name. The following variables would all be saved into session storage:

  • ss_MyVar
  • SS_YourVar
  • _SS_World_Hello

As soon as those variable's values change, they are updated in their respective storage locations.

If in another Captivate project you define ls_MyVar or SS_YourVar (this is case sensitive), then you'll be able to see what value those variables were given in other projects in the course. You could also change the values of those variables, which essentially allow your modules to communicate back and forth with each other.

Note: You can use the xcmndFlushStorage command variable to clear local and session storage data.

Get Variables

Another tried and tested way for web pages to be able to communicate with each other is through the GET variable method.

Go to www.youtube.com and search for Infosemantics. You'll probably find the URL will change to this: https://www.youtube.com/results?search_query=Infosemantics

Notice how first there is a ?. This question mark designates everything that comes after it as being GET variables. What are GET variables? Well see how after the ? it says search_query this is the name of a GET variable. After the name, there is a =. This tells us everything to the right is what the search_query variable equals. So in the end: search_query = Infosemantics.

Now click on the URL and then change the ending to say: ?search_query=Adobe

When you press enter, the page will refresh with a new list of videos relating to Adobe. Tacking these variables on the end of the URL is basically an easy way of sending information between one page and another.

CpExtra allows you to create user variables which can read the value of these GET variables thereby making them available for you utilize in Advanced Actions.

To make a GET user variable, just put get_ in front of its name (not case sensitive). So if you wanted to create a variable that would read the value of the search_query GET variable shown above, you should create a variable called: get_search_query

What if you wanted to use multiple get variables in your course? For example, you had the following variables (all of which are valid BTW)

  • get_username
  • GET_userrole
  • _get_usergender

When linking to the course, you could supply these variables values with a URL like so: www.example.com/index.html?username=Karen&userrole=manager&usergender=female

You can use any number of GET variables, as long as you separate each of their values with a & symbol.

What if in the URL we defined the value for get_username, GET_userrole but NOT _get_usergender? In that case, _get_usergender would retain the default value you set up when you defined the variable.

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!