TImer within a course (Javascript help?)
Jul 29, 2020
Bit of an unusual one.
I have created a Treasure Hunt in Storyline. Players follow clues to walk around our venue, entering number or text entries to progress to the next clue (slide).
I thought I was being clever and added some Javascript I found on the forum to record their time in hours, minutes and seconds.
BUT - the players are using their phones. It's now obvious that they will be locking their phones whilst walking to the next location, using other apps like googlemaps etc. All of which minimise the browser and pause the timer. Argh!
Its all remote so we can't have someone physically there to record start and stop times. I originally had an email populated with the time and sent over at the end of the hunt. But we now know that it isn't an accurate time.
Does anyone have any suggestions on how to record a time, bearing in mind it will be published for web and all mobile?
My idea so far: Is it possible to use JS to record and store the time at the start of the game, then do the same again at the end. Then use the email trigger I have created to send these two times back to base?
I guess if it was I could do more work to calculate the difference between both times.
Any help of further suggestions massively appreciated!
thanks
4 Replies
Hi Martin,
I tried to answer this twice last night, but this site kept crashing. If this message makes it, I'll try again.
Yes, what you want to do is possible, Getting current time with Javascript can be done, but it does take a bit of work. The following bit of code will get the current time in a readable format, and place it in a Storyline variable which I called "StoryLineVariable". Be sure to update this to your text variable in Storyline.
If you want to calculate a difference, you can do that too. First you would need to save the first date in a variable as milliseconds.
Then you would need to retrieve that information to use in your calculation for a difference when you get the new date.
I hope this helps you. In Javascript the "//" indicates that the rest of the line is a comment, and I used that to comment my code for you so you can see what is happening.
Dave
Ah thank you son much Dave!
Really appreciate it. Think I am just about there. Complete Javascript novice but I've learnt a lot in the last 24hours!
I've ended up with a combination of the above and built in variables / triggers.
Essentially used JS to grab the time when the game begins, then again at the end. With those two times, I've converted the hours from the first time into minutes (by x60) then adding on the minutes from the first time. Then it does the same with the second time.
Then use a bit of JS again to work out the difference.
Really interesting, if a little bit of trial and error. Testing it now, thanks for your help!
Cool!
I'm glad that worked out for you.
Dave
This discussion is closed. You can start a new discussion or contact Articulate Support.