Quiz showing Elapsed Time


Today's posting is about advanced actions but not complicated. This is why this is very well suited for users who want to start with advanced actions and variables. I'm trying to answer a question from the Captivate user forum: "I would want the total time taken for the quiz to be displayed...".


Play with this example to see a possible solution, realized with some advanced actions. After the introduction slide the time spent on each question slide will be stored and displayed on the next slide. The total time spent on the quiz will be visible as well. Both will be showed in seconds. On the score slide the total time of the quiz is displayed, either in seconds or in minutes. If it is a really long quiz, it would also be possible to display in hours of course  :-). I will explain briefly the variables and advanced actions used. In the Gallery you'll find a screenshot of each advanced action.


I used the system variable cpInfoElapsedTimeMS and created some user variables:
  • v_start will store the start time for a question (in milliseconds), reused on each question slide
  • v_end  will store the end time for a question  (in milliseconds), reused on each question slide
  • v_duration will store the time spent on a question (in seconds), reused on each question slide
  • v_total will store the time spent on the quiz so far (in seconds)
  • v_help is a variable used to transform the total time to minutes 
  • v_minutes will store the total time spent on the quiz in minutes
On the second question slide, a text caption, labeled InfoTime shows the value of the variables v_duration and v_total. This Text Caption is set to display for the rest of the project and will be hidden by an advanced action on entering the Score slide. For the moment there is no possibility to have a 'mask' to display the time, sometimes you'll see a lot of decimals.

Advanced actions

I have included all the advanced actions as screenshots. Have a look at the image gallery. There are 3 advanced actions:

1. SetStart

This standard action is executed on entering the first Question slide. It populates the variable v_start with the value of the system variable cpInfoElapsedTimeMS at that moment. 

2. StartNext

This standard action is executed on entering all Question slides with the exception of the first one. There are more activities here:
  1. the user variable v_end gets the value of  the system variable cpInfoElapsedTimeMS at that moment;
  2. the variable v_duration is calculated from  v_end and v_start; it is in milliseconds after this statement
  3. the variable v_duration is translated to seconds
  4. the variable v_total is recalculated (in seconds)
  5. the variable v_start is reset to the  value of  the system variable cpInfoElapsedTimeMS at that moment to start the chrono for this question

3. EnterScore 

This conditional action is triggered on entering the score slide. It has 2 decisions, the first Standard is really a standard action, the second Minutes is a conditional action. If you are puzzled about this combination of standard and conditional action, please check this article Combining Standard and Conditional in one Advanced Action.

3.1 Standard decision
  • hides the Text Caption TimeInfo (that was displayed for rest of project)
  • repeats the statements 1-4 of the action StartNext; we do not need 5, because there is no question slide anymore
3.2 Minutes decision
On the score slide you have 2 Text Captions to show the total time spent on the Quiz; initially both are invisible: 
  • YesMinutes shows the total time in minutes and will be set to visible if the total time is greater than 60 sec; you'll find this in the Then part of this decision
  • NoMinutes to show the total time in seconds, will be set to visible if total time is smaller than 60 sec;  you will find this in the Else part of this decision
Let me know if you disliked or liked this explanation. And if you have more questions, do not hesitate...

16 responses
Hi there! I've been trying to get the timer coding to work and I'm having a few issues. I'm using Cap 5 and creating a quiz that I want to publish as an .exe file. The TimeInfo text caption is not hiding and the total time is not displaying. Just the text captions that say YesMinutes and NoMinutes. What am I doing wrong? I've followed your screenshots to the letter.
Bit difficult to judge without seeing your file. Did you insert Yesminutes and NoMinutes as variables into the Text Captions by using the X-button in the Properties panel,, Format accordion (next to Insert and the Symbol icon)? They should show up in the Text Caption during editing between double $$'s. Is that the case? If you are not familiar with using variables, please check my blog posts about variables: http://lilybiri.posterous.com/curious-about-variables-in-captivate-4-5 and http://lilybiri.posterous.com/unleash-the-power-of-variables-in-captivate-5
This is my first attempt with variables. I did as you suggested and added the variables via the X-button. I see the $$YesMinutes$$ however, the accumulated time is not appearing after publishing. I'm not sure what I need to do to make the cumulative time appear.

I'm not sure if you can view this, but please try.

M:\Private\TRAIN_S\Current Projects\Training Projects\Computer Skills & Keyboarding\PC Skills Assessment - Part 1 (Timer).htm

I did as you said and I entered the variables via the format accordian. I see the $$ however, the cumulative time doesn't appear. It's an empty box.
I cannot access your file. Did you attach the action StartNext to the event 'On Enter' for EACH question slide, except the first one? Perhaps you forgot to attach all advanced actions, double - check everything. It seems that the variable v_duration is never populated, which means that you will not have a total time - variable v_total either. Did you create all the variables, and be careful they are case sensitive, as are the action labels.
No I dod not attach the action StartNext on each slide. I will give it a go.
"Did you attach the action StartNext to the event 'On Enter' for EACH question slide, except the first one?"

I am not sure how to do this. Can you walk me through it?

In the Properties Panel of the slide, Accordion Action you have On Enter. Default action is 'Continue', open the dropdown list and choose 'Execute Advanced Action' and indicate the action. There is an action for each slide: SetStart for the first Question slide, StartNext for all the other Question slides and EnterScore for the Score slide.
Great! Thanks for the process. I republished my project and it still doesn't give me a cumulative time. As you mentioned earlier, the v_duration must not be working. When you create this variable did you enter 1000 as a variable or literal value? I entered it as literal and typed in 1000. I created v_minutes and v_help with a literal value of 60. Is this correct?
Or do I need to assign the value when I actually create the variable? I noticed there was a value field under the name and above the description when I added a new variable.
No need to add a value when creating the variables, they do get their value by the advanced actions. One example (I explained it all in this blog post, please do read it thoroughly): v_start will get a value on the start of the slide by the advanced action SetStart (for the first question slide) or by StartNext for the other question slides. As I told you: check if you do have those actions in the proper place.
I'm reopening this thread as It is the only resource on the web close enough to what I'm looking for.

I'd like to create a text box with a live chronograph MM:SS to show the duration of an Action I'm demoing on a software.

I can display the current time, the Epoch time or time enlapsed but as soon as it gets to working with operators I get error NaN or nothing. Could you create a tutorial to address this?

Do not really understand the question? Perhaps you'll have to use a variable that is calculated from the (dynamic) elapsed time and the (fixed) elapsed time at the start of the action that you'll have to store in another variable.
Hi, I hope you will be reading and replying this. I am using Captivate 7 and new to Captivate. I am having trouble about the time start (SetStart Adv Action). When I tested my project, on the second slide, the time does not look like it is in milliseconds, it looks like it is in nanosecond. For example, the time is 1396023760.95. By calculation of v_duration/1000, it will still give 1396023.76095 which I know is not in seconds. =( I already checked everything but nothing works. Therefore, this creates problem to the rest of the project in counting the elapsed time. Thank you.
Hi Lieve, Thanks for all of your great blogs! I am wondering if we are missing a step somewhere. You wrote, "On the score slide you have 2 Text Captions to show the total time spent on the Quiz; initially both are invisible" These text captions are YesMinutes and NoMinutes. Then in the EnterScore advanced action, depending on whether the learner took more or less than 60 seconds, the YesMinutes or NoMinutes text caption displays upon entering the score slide. What I cannot see is WHAT content goes into the YesMinutes or NoMinutes text captions. In a response to another comment you said to add YesMinutes and NoMinutes as variables but, again, there is nothing in the advanced actions assigning any values to those variables or using those variables in an expression. Could you please shed some light on this? Thanks.
1 visitor upvoted this post.