Forum Discussion
Timer issue
- 3 months ago
Try:
var Total = getVar("Total_Time"); var minutes = Math.floor(Total / 60); var seconds = Total % 60; var formattedTime = minutes + ' minute(s) ' + (seconds < 10 ? '0' : '') + seconds + ' second(s)'; setVar("Split_Time", formattedTime);
or:
var Total = getVar("Total_Time"); var minutes = Math.floor(Total / 60); var seconds = Math.floor(Total % 60); // <-- Floor seconds to remove decimals var formattedTime = minutes + ' minute(s) ' + (seconds < 10 ? '0' : '') + seconds + ' second(s)'; setVar("Split_Time", formattedTime);
to remove decimals.
Try:
var Total = getVar("Total_Time");
var minutes = Math.floor(Total / 60);
var seconds = Total % 60;
var formattedTime = minutes + ' minute(s) ' + (seconds < 10 ? '0' : '') + seconds + ' second(s)';
setVar("Split_Time", formattedTime);
or:
var Total = getVar("Total_Time");
var minutes = Math.floor(Total / 60);
var seconds = Math.floor(Total % 60); // <-- Floor seconds to remove decimals
var formattedTime = minutes + ' minute(s) ' + (seconds < 10 ? '0' : '') + seconds + ' second(s)';
setVar("Split_Time", formattedTime);
to remove decimals.
- CajaPopularM7042 months agoCommunity Member
Hello Nedim
Hoping You're ok.
I've been having another issue, this time with a time limit, I want it to be 20 minutes, but for some reason no variable attached to the timer (var Split_Time) works, or even jumps immediately to the 20 minutes and stops the course.
For example, I added a new variable, Time_End, and gave it a value of 0, and added a condition to jump to a slide if it becomes 20, because I attached it to the var minutes used in the code you provided me above. In this case, Time_End becomes 20 immediately and stops working.
If you could help me, once more, I would be grateful.
- Nedim2 months agoCommunity Member
You can modify the existing script I shared earlier by adding a new True/False variable called TimeUp. Update the code to check when the total time reaches or exceeds 20 minutes (1200 seconds) and set TimeUp to true when that condition is met. Then, create a trigger to jump to the next slide when TimeUp changes to true. If you want a different time limit, simply update the condition in the script to the desired number of seconds, less or more than 1200 seconds, to fit your needs.
I’ve attached the updated Storyline file and the script on Slide 2.
var Total = getVar("Total_Time"); var minutes = Math.floor(Total / 60); var seconds = Math.floor(Total % 60); var formattedTime = minutes + " minute(s) " + (seconds < 10 ? "0" : "") + seconds + " second(s)"; setVar("Split_Time", formattedTime); // Set TimeUp = true when 20 minutes (1200 seconds) is reached or exceeded if (Total >= 1200) { setVar("TimeUp", true); } else { setVar("TimeUp", false); }
.
- CajaPopularM7042 months agoCommunity Member
Nedim
Thanks again for all your help.
I'm sorry to tell you that adding the trigger causes the timer to not work properly, I attached the Storyline file, in slide 2 I added a trigger that, when "TimeUp" becomes true, jump to the previous slide. If I run the whole project, when I click slide 2, it jumps immediately to slide 1, not even waiting for 20 minutes.
So I'm not sure if I should be working instead with the project variable "Project Elapsed Time".
Hoping you're good
Related Content
- 9 months ago
- 31 days ago
- 3 months ago
- 2 years ago