Lectora Basics: What Is a Variable?

blog_Basics_Variables

“I don’t get variables! I’d rather be nibbled to death by ducks than try to deal with them!”

Are you a Lectora® user who cringes at the mere mention of the word “variable?” You are not alone! The concept of variables is very simple, but for whatever reason, is difficult to grasp for a lot of people. So I thought I’d begin this blog series with a topic that isn’t even specific to Lectora. It’s just a concept that, once understood, opens up all sorts of new possibilities for things you can do with Lectora, like custom navigation and branching, simulations, swapping content based on user input, gamification… Pretty much anything you can dream up!

In trying to think of how I might describe what a variable is to people new to the concept, I did a web search for “variable definition.” Most of the resources I found use a lot of technical terms and get way into the weeds before they even tell you what it really is! And while all those details and terms may be important eventually, they are not needed to understand the basic concept.

So to verbally define it as simply as I can think to, a variable is a container! It’s just a boring old container—like a basket, a bucket, or a beer mug. And like most containers, a variable can contain just about anything you want to put in it, or contain nothing at all. (Ok, so you can’t put real beer in a variable, but you can put the word “beer” in a variable! We’ll talk more about that in a minute.)

To be a little more specific, a variable is a named container. And to create one, all you have to do is pick a name, like basket, or bucket, or beer_mug. The name can be anything you want as long as you stick to a few simple rules:

• Use only letters, numbers, dollar signs $, and underscores _. (No spaces, which is why I put an underscore in beer_mug.)

• Begin the name with a letter, a dollar sign, or underscore. (A variable name cannot start with a number.)

• Don’t use names that are already used by JavaScript. (JavaScript is the programming language underlying the functionality of what Lectora produces. You can find a list of JavaScript Reserved words here: http://www.quackit.com/javascript/javascript_reserved_words.cfm.)

• Don’t use names that are already used by Lectora. (You can see what names are already used by Lectora on the Reserved tab of the Variable Manager.)

wendymillerblog1

Best practice for variable names is to choose something that describes what you plan to put into your variable/container. Use names like totalQuizScores, or popup_is_open, or numberOfTries, or currentVocabWord.

Like I said before, you can’t put real beer in a variable, but you can put a representation of beer in a variable by using the word “beer.” So when I said you can put anything you want in a variable, the catch is that it has to be represented by characters or numbers or both.

Some of us are visual thinkers and hands-on learners. I am definitely one of those people and did not catch on to the abstract concept of variables until somebody actually showed me what a variable is. So I built this little interactive piece (in Lectora, of course!) that may help those of you who are like me to see what a variable is. Play around with it and see if it starts to become clearer.

So that’s it really! A variable is just a named container, a place to store stuff for later use. In my next blog, I’ll explain how to make a variable in Lectora, how to put stuff into it and get stuff out of it, and why you would even want to use your own user-defined variables in the first place.

Liked this article? Subscribe to the Everything eLearning Blog for more Lectora Basics, free resources, and product news.

Lectora Basics is your intro to eLearning authoring with Lectora. In this blog series, Wendy Miller, Lead Content Developer here at Trivantis, will introduce you to fundamental concepts in Lectora. Wendy is a visual designer and computer programmer with extensive experience developing software, courseware, web sites, games, and multimedia.

Other Lectora Basics articles:

• Lectora Basics: Using User-Defined Variables

• Lectora Basics: About Question Variables