Restart Course, but keep value of one variable
Jun 26, 2023
I have a course with a lot of variables in use.
Resetting all used variables manually is error prone, so I am using the "restart course"-trigger that sets back everything.
It is kind of a quiz with a restricted amount of tries.
Therefor, I have a number-variable, with a default-value of 3, and substract 1 from that variable for each try.
When the variable is 0, no more tries are left and the quiz ends.
The problem is: restarting the course also sets back the variable that counts the number of tries.
I do can change the variable after the restart-trigger and set it to a certain number. But as it is already set back to its default value (3), substracting does not work anymore (as it will always end up being 2).
Does anyone know a way to keep the value of my variable, while setting back all other variables? Or some other work-around?
6 Replies
you can save/restore variables in the global window object with some lines of javascript
example: var1 is permanent, var 2 not
trigger on button click restart (before execute "restart course")
trigger on start timeline ot the first slide
result:
https://360.articulate.com/review/content/2c375a55-d99a-4f05-b6e0-8e9eaa9ff2d1/review
Hi Jürgen,
Thank you.
That works well.
Unfortunately, if I reload the page also variables stored in the global window are restored to there initial value. Can I store them somewhere else?
The project is part of an exam, so users should really only have a defined number of attempts.
here is an example where the counter is permanently saved in localStorage
trigger on button click restart
trigger on start timeline ot the first slide
https://360.articulate.com/review/content/3c4845c0-6b8b-46d8-b25f-a3f581b53752/review
this remains until you delete the Local Storage manually
CAUTION: the solution does not protect against manipulation by the learner - you can simply overwrite the value in the browser
Perfect, thank you so much Jürgen.
Hi Jürgen,
May I ask you one more thing:
I have got this countdown JS:
var player = GetPlayer();
var zeit = player.GetVar("zeit");
var downloadTimer = setInterval(function(){
if(zeit < 2){
clearInterval(downloadTimer);
}
zeit -= 1;
var player = GetPlayer();
player.SetVar("zeit", zeit);
}, 1000);
It works fine, but now I am looking for a way to reset the counter.
As it is now, the counter counts down to 0.
But if the user has successfully completed the task within the given time, I need to reset the counter for the next task.
I tried changing the value of "zeit", as this is the variable that JS loads.
But unfortunately that does not work. I attached a sample file.
here a small patch
important: save the timer number in the window object, so other scripts can interrupt the timer
https://360.articulate.com/review/content/c8452454-0f9d-4144-bde2-d681821a76aa/review
hint: use for formating scripts here in the forum the function "Formats > Blocks > Pre" not "Formats > Inline > Code"