Organization of variables

Nov 16, 2021

Hi There,

I try to organize my variables so that they make logical sense to me, because normally I have a lot of them. My system is to name each variable based on the slide number: SlideNumber_LayerNumber_Variable (e.g. slide 2.1 will have variables named 210_0_Variable_1, 210_0_Variable_2 (base layer), layer one of the same slide will be 210_1_Variable_1, 210_1_Variable_2 and so on. 

It seems to work fine for organizing my projects, until I decide I want to add a new slide before one that has variables. Storyline renames all the slide numbers and then all the variable references are "incorrect" (meaning, my system is "broken"), forcing me to rename all the variables. The current project I am working is a quiz that has 20 questions and about 50 variables.

In addition, I will use these quiz questions as part of a larger recertification test. When I add the questions to the other project, all of the variables will be renamed to something completely unsatisfactory (hotspot 1, hotspot 2, numeric entry 1, numeric entry 2 etc.), which will force me to rename all of them again.

I'm curious if anyone has a better way of organizing their variables so that they make sense, without having all the extra work of renaming them...?

 

7 Replies
Joseph Francis

The way to organize your variables is the way...that makes the most sense to you. A passage in the Wikipedia article Naming convention (programming) sums it up nicely:

The choice of naming conventions (and the extent to which they are enforced) is often a contentious issue, with partisans holding their viewpoint to be the best and others to be inferior. Moreover, even with known and well-defined naming conventions in place, some organizations may fail to consistently adhere to them, causing inconsistency and confusion. These challenges may be exacerbated if the naming convention rules are internally inconsistent, arbitrary, difficult to remember, or otherwise perceived as more burdensome than beneficial.

Having developed in multiple languages over the years, which touched many systems, databases, and other applications, I can say my variable naming conventions...have continued to evolve. One convention I do try to stick to (for now!) is name the variable based on its type (Boolean, Numeric, or Text) and what its content/function is (show/hide image, employee ID, User's Name). So I might have variables like bolDisplayBackgroundImage, numEmployeeID, or txtUserFirstName.

 

Phil Mayor

I try not to use slide numbers in variables for the reason you explain, also I try to ensure the use is explained in the name. I reuse a lot of variable names for the same function in all courses, a carousel will always use he same variable name so if I want to reuse slides later on it doesn't break anything.

As variables are really slide agnostic you shouldn't need a lot of slide specific variables.

I always ask myself the same question when creating variable:

Is it for one slide or many slides? If it is one slide can I use something else such as states?

 

Walt Hamilton

The short answer is that if you are going to keep this convention, and change slide numbers, yes, you are going to have to rename variables manually. Although I have had better luck with variable names by inserting slides, rather than copying questions or slides,  moving variables to new projects usually includes renaming a lot of them.

It is hard to argue with Joseph’s idea, that if they don’t make sense to you, they won’t work for you. Still, tying names to function rather than location seems to me to be a method of lightening a lot of the load you describe. Also, one wonders what happens if it becomes necessary to reference one of those variables on a different slide.

If you don’t use these variables on different slides, and do use them to refer to objects (as the renaming to hotspots seems to suggest), there is another way to lighten the load. You might consider naming objects, and referring to those by name in your triggers, rather than assigning them a variable, changing the variable, and referring to it.

Ultimately, there really is no way around your dilemma in SL.  Your best bet is to see if there is some workflow change that can help.  At the very least, naming the slides, and using those names instead of the slide numbers in the variable names can help. At least you won’t have to rename all variables if one slide is added to the beginning of the project.

William Ryan

Thanks all for your replies. Maybe I have a misunderstanding of a basic point. Let's say I have 4 numeric entries called NumericEntry1, NumericEntry2, NumericEntry3 and NumericSum.  On Slide A, NumericSum, is the sum of NumericEntry1 and NumericEntry2. On Slide B, NumericSum should be the sum of NumericEntry1 and NumericEntry3. I thought that the variable states will persist from slide to slide, so for this reason I was making them slide specific.

Are the variable states reset from slide to slide, or should I manually reset them when the slide timeline starts? This could really slim down my variables if I could reuse them on different slides. Of the quiz I referenced in the beginning, I have numeric entries in 6 of them, Adding up all of the numeric entry fields, I have 45 of them on 18 slides so far in this project. There are 21 unique numeric entry names. Some of these are used in other slides. Some of these are summed, and the "correct" answer are in 6 additional numeric entry fields. one example (the "busiest", has 10 numeric entry fields that are summed to the 11th, Of the 10 numeric entry fields, there are 4 which can be used in other slides.

Joseph Francis

In Storyline, all variables are global. Unlike JavaScript, there aren't variables which have either a Function Scope, a Local Scope, or a Block Scope.

If you're going to "park" entered numbers/text into a different variable, or manipulate the entered data and don't need to refer back to that "raw" number/text, then by all means, reduce the number of Text/Numeric Entry variables to the minimum you need.