Forum Discussion
Reset multiple variables to default values
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
- SteveGannonCommunity Member
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.
- ChrisAmmonCommunity Member
Thanks for the quick reply Steve. Even if that did work, my scenario is only one scene within a larger course. I have a scene of more traditional instructional slides and then the scenario is in another scene. Users can restart the scenario scene without restarting the whole course. Cheers!
- SteveGannonCommunity Member
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.
- KevinDixon4Community Member
You could also set triggers to set the var. back to ("what ever it starts as) when they click the button to restart
- SteveGannonCommunity Member
That's how I would do it too, Kevin (with triggers), but Chris was trying to come up with a way of resetting the variables (he has 20 of them) without having to add 20 triggers.
- ChrisAmmonCommunity Member
Works like a charm, Steve. Thanks so much for the help!
- JillFreemanCommunity Member
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?
- SteveGannonCommunity Member
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.
- JillFreemanCommunity Member
Darn. I need to request this as a new feature. Thanks!
- UdaySingh1Community Member
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
Related Content
- 12 months ago
- 12 months ago
- 12 months ago
- 12 months ago