What are variables and how (and why) should I use them?
Feb 20, 2024
I got home last night, and the cat insisted he had not been fed all day, and was STARVING. I hadn't been there all day, so I didn't know, and my wife was off to her quilting party, so I couldn't ask her. Fortunately, she left a sticky note on the counter that said "I fed the cat", so I knew not to feed him again.
The note she left me is the variable. I couldn't see her feed the cat, but I could see the note and know what went on while I was gone. Storyline is just like I was. One slide has no way of knowing what happens on another slide, but it can read a message left for it in a variable, and know what the learner did on another slide, provided you, the developer, used those actions on that other slide to change the contents of a variable.
The cat got pretty insistent, so I gave him a snack, crossed out her message, and wrote, "He's also had a bedtime snack", and went to my meeting.
The note is the variable. Everybody can see it, and it never changes unless you, the developer, create a trigger to change it.
My wife is getting older (I'm not, just she), and takes a bunch of medicines. She puts them in one of those little plastic gadgets with seven boxes. Every night, (if she remembers :) ) she looks in the box for that day. If it is empty, she knows she has taken her pills that day.
The pill box is the variable. She can't always remember everything, but if the box has pills in it, she knows to take them.
Variables are designed to be seen everywhere, but not heard (much like small children of a previous generation). SL cannot multi-task, so only one slide at a time can be active. SL has no memory, so when a slide becomes active, it can't know what went on while it was hibernating. That's why variables were invented. Each slide can look at the note (variable) and by seeing what is on there now, it can know what went on somewhere else, or some other time. I couldn't hear my wife write the note, but I can read it and know what went on at home while I was not there.
Variable aren't actual things, nor parts of your project, just like the pillbox isn't part of my wife's medicine. They are just post-it notes to carry information from one part of the project to another, and are most useful in trigger conditions.
10 Replies
Walt, I think that's such a helpful analogy!
I learned about variables in the days of HyperCard. (Yup. HyperCard. I guess that proves I'm in the "older" category—like your wife is and you aren't. 😉 ) As I recall, the analogy I heard back then was that a variable is like a bucket for carrying info. But I think the post-it-note concept is better.
Of course, what you can enter is based on the "style" (type) of the "note" (variable): text, numbers, or T/F.
For others who find this discussion thread, I'll add this: It’s worth the effort to learn about variables and trigger conditions, because they provide the real power in Storyline. Here’s the User Guide info:
Judy, that's a good point. And flipping Dirty/Clean sign is like using the toggle command for a T/F variable. It changes it to whatever it isn't.
Not that old, I created a lot of things in HyperCard :)
I love those analogies, Walt. They make variables so easy to understand—especially for those of us who have bossy cats that like to lie about never having been fed ever!
And Judy, either none of us in this thread are old or ALL of us are old, because I used HyperCard back in the day too.
Walt & Bianca: Both HyperCard users! Wow.
And did you ever use it to control a videodisc? (Remember those?)
BTW, I referenced HyperCard in a recent feature request. I want Storyline to let me insert text before or after the existing text in a variable. For example, to build a list. Like I could easily do in HyperCard...
Oooh! I only used HyperCard with some of my friends to create little exploration games. I definitely didn't do anything like this.
And glad to hear you submitted that feature request. That would be useful functionality.
Variables in programming are named storage locations that hold data. They facilitate dynamic data handling, improve code readability, enable value reuse, aid debugging, and support mathematical/logical operations. Use them to store and manage data, respond to user input, and make your code more flexible and readable.
"are named storage locations" does not mean "what variables are called", it means that variables are storage locations that have actual names. You can give a variable any name you want (within the legal parameters of the language), but best practice demands that the name is descriptive and congruent with the names of similarly used variables.
Thanks for taking the time to share the solution....Your help is greatly appreciated!
I only used HyperCard with some of my friends to create little exploration games.
It's great to see such a rich discussion about variables! They're like post-it notes carrying information between different parts of a project, just like the note left by Walt's wife communicates what happened while he was away. Variables are crucial for allowing slides to communicate with each other, making interactive experiences possible. Thanks for sharing your insights, everyone!