Lectora Basics: What Is a Variable?
“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 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 an underscore. (A variable name cannot start with a number.)
• 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.)
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 that’s it really! A variable is just a named container, a place to store stuff for later use.
This article last reviewed Dec, 2015. The software may have changed since the last review. Please visit our Release Notes to learn more about version updates.