Reset multiple variables to default values

Jul 31, 2014

Is there any shortcut for reseting many variable to their default values? I'm creating a scenario based training in which I have about 20 variables tracking user progress. If they choose to restart the training I need to reset all of the variables. Can that be done with a single trigger or javascript versus adding 20 individual triggers to my Restart button? Thank you!

39 Replies
Steve Gannon

I think the expected behavior when using the "Restart" trigger to restart a course, the variables will be reset to their initial values set in the Variables panel. Unfortunately, I recall that a few months ago there were some reports of this not working properly. I just tried it and it doesn't work. In fact, it results in a blank screen. Therefore, for now Chris, I think you're stuck with re-initialilzing the variables with triggers.

Steve Gannon

Thanks for the clarification, Chris. In that case, you could execute some JavaScript via the Execute JavaScript trigger to reset the variables, such as in the code between the dashed lines below:

---------

var player = GetPlayer();
player.SetVar("variable1", "John");
player.SetVar("variable2", "Doe");

----------

You would replace "variable1" and "variable2" with the variable names just as they're spelled in your Storyline file. The text in quotes after the variable names represent the values you want to reset the variables to. Remember you'll need to publish your file before you can test the JavaScript. And remember it won't work in the AMP app on the iPad.

Jill Freeman

That is a great solution, Steve. Along similar lines, do you know a way to reset an individual slide with javascript (or other)? We have a custom Replay button since we are not using the Storyline player with the Replay button. It needs to reset everything on the slide - and we need to keep the Resume to Saved State property on all slides. Any ideas?

Steve Gannon

Hi Jill,

I understand what you're trying to do but off the top of my head, no, I don't know of a way to do this.

My first thought was that you could use JavaScript to get the value of cmi.suspend_data, such as:

var progress = lmsAPI.GetDataChunk();

...and then edit the string stored in 'progress', sending it back using lmsAPI.SetDataChunk, but that's pretty sketchy. Even if you could decipher the string, it would be pretty hazardous to try to update it I would think.

Uday Singh

Steve Gannon said:

Thanks for the clarification, Chris. In that case, you could execute some JavaScript via the Execute JavaScript trigger to reset the variables, such as in the code between the dashed lines below:

---------

var player = GetPlayer();
player.SetVar("variable1", "John");
player.SetVar("variable2", "Doe");

----------

You would replace "variable1" and "variable2" with the variable names just as they're spelled in your Storyline file. The text in quotes after the variable names represent the values you want to reset the variables to. Remember you'll need to publish your file before you can test the JavaScript. And remember it won't work in the AMP app on the iPad.


Hi Steve,

Thanks for your support. I tried the code:

---------

var player = GetPlayer();
player.SetVar("variable1", "John");
player.SetVar("variable2", "Doe");

----------

It's working fine in almost all the browsers except IE7. Is that code is not compatible for IE7 browsers? Please provide me some solution, how can we use this code in Internet Explorer 7 browser.

Awaiting for your helpful response.

Thanks,

Uday

stacey perry kramer

Hi,

I have about 25 variables that I would like to reset with the click of a reset button. All of these items are on a single slide with layers. I added a trigger to the reset button using the javascript above but it is not resetting the variables. Is there another step that I might be missing?

Should this code reset the variables on the slide if the reset button is on the same slide? Does the reset button need to be on a different slide in order for the timeline to reset first?

Does my code look correct or am I missing something?

var player = GetPlayer();
player.SetVar("greenbeans", "False");
player.SetVar("saladmix", "False");
player.SetVar("mixedveggies", "False");
player.SetVar("slicedtomatoes", "False");
player.SetVar("topsirloin", "False");
player.SetVar("yogurt", "False");
player.SetVar("grilledsalmon", "False");
player.SetVar("milk", "False");
player.SetVar("mixedfruit", "False");
player.SetVar("pasta", "False");
player.SetVar("pudding", "False");
player.SetVar("quinoa", "False");
player.SetVar("apple", "False");
player.SetVar("beans", "False");
player.SetVar("slicedapples", "False");
player.SetVar("blueberries", "False");
player.SetVar("bread", "False");
player.SetVar("brownrice", "False");
player.SetVar("cherries", "False");
player.SetVar("cottagecheese", "False");
player.SetVar("greenbeans", "False");
player.SetVar("grilledchicken", "False");

I greatly appreciate any input.

Thanks!

Stacey

Steve Gannon

Stacey: Based on your description and code, this should work. All of the variables you have listed are defined in Storyline, spelled exactly that way (all lowercase), and are True/False variables (not number or text), correct? If so, have you tried publishing your file and placing the published output on a web server? Sometimes, JavaScript won't run when the published output is launched from the local drive.

Uday: I apologize for the late reply; I'm just seeing your note now. I no longer have IE 7 on any of my machines so I can't say whether your JavaScript should run in that environment. When trying it out, be sure you're testing the content from a server and be sure JavaScript is activated in the browser (sometimes a user's security settings are set quite restrictive and may block JavaScript).

Yvette Healey

GREAT thread! I have incorporated JavaScript to reset a large number of variables, and it's working great. The PROBLEM is that, after all variables are reset to a value of FALSE (after one particular value having been true), it appears as though a user going through the course subsequent times, triggering Variable 2 to be "true" on the second go-round, that the variable 2 is NOT marked true by the same trigger that successfully made Variable 1 "true" the first time through the course. In other words:

1) Initial course run through, Variable 1 triggered from "False" (default) to "True"

2) Element later in course successfully recognizes Variable 1 as "True" and behaves properly!

3) User clicks "return to menu", which executes JavaScript to reset all variables to "False" (regardless of which variable the user clicks).

4) User runs through course a second time and Variable 2 is triggered from "False" (default and result of JavaScript execution during Course Round 1) to "True".

5) But when user gets to element later in course (as in 2) above), the variable is NOT recognized as true. In fact, ALL variables are false, regardless of which variable was set to True earlier.

What did I do wrong? Is there some software issue of which I am not aware? I DID test this in a live LMS Environment (not just on course preview mode in Storyline 2).

Thank you for any help! I have to launch this course in 2 days, and this is my last little (?) glitch! The other elements of the course are working beautifully!

Yvette Healey

Thanks, Ashley! I am adding the course here as an attachment (formatted for Web Delivery). As an aside, should I try using numerous triggers in Storyline (no Javascript) to reset the variables instead of JavaScript?

Testers: Please begin the course by clicking on the "First Floor" caption. Mouse over and choose a section and remember your color. Click on that section and view the evacuation route. Then hit the "Proceed to Outdoor Meeting Location" button that pops up at the end of the route. There is a brief layer or two of info, and then you get to the layer that shows you the color-coded outdoor location signs. Remember WHERE your sign is. On the next slide, click the sign that matches the color whose route you just viewed. On the "correct" screen, click the "Main Menu" button and try a SECOND route of a different color. Note how, after viewing the route for THAT second department/color, clicking on the correct outdoor sign color does NOT yield a correct screen :-(

Thank you for any help!

Ashley Terwilliger-Pollard

Hi Yvette,

It sounds like something you could set up with regular triggers and variables - but I'd hate for you to go through that if it's just a line of code or something off in the javascript set up. Hopefully folks in our community are able to weigh in here and if you don't hear anything by tomorrow it may be worth starting a new thread with the Javascript element in the title so that they're able to spot it easily. :-)