Forum Discussion
Timer issue
- 4 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.
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.
- Nedim3 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); }.
- CajaPopularM7043 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
- Nedim3 months agoCommunity Member
Honestly, I haven't tested this with multiple slides, and the behavior you're describing is confirmed on my end, and it's indeed a bit strange. I haven't been able to fully solve it the way it currently works either, so let’s explore another approach:
Instead of using the TimeUp variable, you can delete it along with all related references in your JavaScript code. It’s no longer necessary for this workaround. Use the same code as on the first slide.
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)Jump to slide trigger: we're slightly increasing the condition range (e.g., from 1200–1201) to ensure the trigger is more reliably caught. We are using Total_Time variable value directly.
Also, I just realized something that might be interfering with your setup. You're using Project.ElapsedTime, which measures the total time spent in the entire project. This means the timer never stops, even when you're on other slides. So if the user spends 20 minutes on a different slide and then jumps to the one where the 20-minute condition is checked, nothing will happen, because that condition has already passed before reaching the slide. Just a thought: it might make more sense to use Slide.ElapsedTime instead. However, I’m not sure exactly what behavior you’re aiming for. Test this new approach with a shorter time range first (e.g., between 10 and 11 seconds). If it proves to be working, then revert back to the original range (1200–1201 seconds).
Related Content
- 17 days ago
- 27 days ago
- 17 days ago
- 10 months ago