Forum Discussion
Timing how long an interaction takes.
So my courses have to be timed for credit. I have an interaction which include several slides and pathways. I want to be able to make sure that the participants spend a certain amount of time going through the interaction or repeating the interaction to see different results. Is there a way to make sure an interaction takes a desired amount of time?
- Bernovan-SoestCommunity Member
Lance,
Yes, you can copy and paste the JS code in triggers.
Regarding the calculations:
var player = GetPlayer();
var start = player.GetVar("gsStart");
var end = player.GetVar("gsEnd");
var duration = end - start;
You may want to divide by 1000 because the start and end time is in millisecond.
var duration = (end - start) / 1000;
- JonXieCommunity MemberHello, Sam ! How did you achieve it ? Please kindly share your story file.
Sam Clark said:
With some additional effort, a time-remaining graphic could be added to every slide....
- JonXieCommunity Member
Hello, Berno. Could you screenr how to use your js code ?
- JonXieCommunity Member
Many thanks, Berno! Good job. Another problem--how could I go about achieving remaining time by using JS in this case as Sam did to add it to each slide? Sorry to trouble you !
- RebeccaFleischCCommunity Member
Hi All,
I'm venturing - no really I'm tip-toeing - into Execution of JavaScript. And since I no NOTHING about it, I'm simply using what y'all offer here and C/P into the JavaScript box.So, I really appreciate the Q/A.
I know enough to understand that the trigger names must match the characters inside the Javascript window, e.g., in the case of the gsStart trigger, it matches the characters inside the first set of quotation marks in the player.SetVar line:
player.SetVar("gsStart", d.getTime());
So, I successfully implemented a trigger that shows how much time was spent on a previous slide when the Learner clicks the next button - and to display the time on the next slide. Essentially, I copied what you did, Berno, but using the next button instead of Submit.
What I really want to do is to have a counter that displays a number of seconds count on the current slide. So, nothing would be clicked, it would just count up in seconds. And I'd reference the count inside a text box.
I'd searched the forums a while back for this but didn't find exactly what I was looking for. Perhaps I missed it. Does anyone know how to do this?
And thanks again.
- SteveFlowersCommunity Member
Hi, Rebecca -
You'd need to do this with an interval to repeatedly update the second value. I'll test one out to make sure there's no funny business or side effects and post in a bit.
In the mean time, here are some DYNAMITE references for learning more about JavaScript. The codacademy site is instructional candy. So good. All practice and feedback. Appendto isn't bad either, more demonstration if that's your preference.
- SamClarkCommunity Member
Rebecca Fleisch Cordeiro said:
I know enough to understand that the trigger names must match the characters inside the Javascript window, e.g., in the case of the gsStart trigger, it matches the characters inside the first set of quotation marks in the player.SetVar line:
Probably a typeo, but gsStart is a Storyline variable, not a trigger. If there is a way to fire a trigger in Storyline, it would be by setting a value in a variable to which a trigger is set to fire on that value.Steve's suggestion of an interval timer is the right idea. I look forward to seeing it implemented.
- RebeccaFleischCCommunity Member
Sam, yep was a typo. And I DO understand the difference between triggers and variables ... really Tx for proofing/editing. Don't want to lead people down the wrong path, nor do I want them to think I don't know my whatchamacallit from my elbow.
Steve, tx so much. As I mentioned in another thread to Nancy, I'll need to add this to my ToDo list. In the meantime, looking forward to your post. Oh, there's no rush. Just something I had in mind. And I know you're busy.
- SteveFlowersCommunity Member
The value in the setInterval call "1000" is milliseconds. So that's a 1 second tick.
- JonXieCommunity Member
Thanks a lot, Steve, It's wonderful !