Hi! Thanks so much for the quick response. I'm not too familiar with java script so I was wondering how do i remove the seconds from the display?
I removed the sec from this line player.SetVar("12Hour", hour+":"+minute+":"+sec+" "+am_pm);
And also i deleted this part of the code var sec = date.getSeconds(); if(sec<10){ sec = "0"+sec; }
So now the code looks like this
var player = GetPlayer();
function date_time() { var date = new Date(); var am_pm = "AM"; var hour = date.getHours(); if(hour>=12){ am_pm = "PM"; } if(hour>12){ hour = hour - 12; } if(hour<10){ hour = "0"+hour; }
var minute = date.getMinutes(); if (minute<10){ minute = "0"+minute; }
player.SetVar("12Hour", hour+":"+minute+am_pm);
}
setInterval(date_time,500);
But the seconds appears and disappears every second (refer to attached video). How do I solve this issue? Thanks again, you have been such a great help! :D
That script just there is perfect and it works beautifully for my interface demo which will show the user's current time as they interact with the module.
However, I have a request to show time-based information within the display and I was wondering how could this be adjusted to have a variable display, say, 4 minutes earlier than the current time? Like in a text message timeline, for example.
4.36PM: Diarmaid wrote this.
%12Hour%: Diarmaid wrote this.
4.32PM: Diarmaid thought about writing this.
%12Hour_Minus4Mins%: Diarmaid thought about writing this.
I thought I could just use some mathematics but realised that it's a text string variable so I am stumped.
Thank you so much for the solution Jurgen. That is deeply, deeply appreciated.
If I wanted to use that new script AS WELL as the original, I would obviously have to rename the variable 12Hour to something new, like, 12HourMINUS4, so the only thing I would have to replace in your code would be on line 22,
The functionname is the same too, so you either need to change that too...or change the function so it sets 2 variables. Assuming you using them on the same trigger. If you use them on 2 separate triggers due to the fact Storyline scope is local ( trigger A has no knowledge about trgger B ) you can do as you plan.
9 Replies
Hi Jing,
How about this format?
Hi! Thanks so much for the quick response. I'm not too familiar with java script so I was wondering how do i remove the seconds from the display?
I removed the sec from this line
player.SetVar("12Hour", hour+":"+minute+":"+sec+" "+am_pm);
And also i deleted this part of the code
var sec = date.getSeconds();
if(sec<10){
sec = "0"+sec;
}
So now the code looks like this
var player = GetPlayer();
function date_time() {
var date = new Date();
var am_pm = "AM";
var hour = date.getHours();
if(hour>=12){
am_pm = "PM";
}
if(hour>12){
hour = hour - 12;
}
if(hour<10){
hour = "0"+hour;
}
var minute = date.getMinutes();
if (minute<10){
minute = "0"+minute;
}
player.SetVar("12Hour", hour+":"+minute+am_pm);
}
setInterval(date_time,500);
But the seconds appears and disappears every second (refer to attached video).
How do I solve this issue?
Thanks again, you have been such a great help! :D
Hi,
I think your script is correct.
Anyway, use this script below.
var player = GetPlayer();
function date_time() {
var date = new Date();
var am_pm = "AM";
var hour = date.getHours();
if(hour>=12){
am_pm = "PM";
}
if(hour>12){
hour = hour - 12;
}
if(hour<10){
hour = "0"+hour;
}
var minute = date.getMinutes();
if (minute<10){
minute = "0"+minute;
}
player.SetVar("12Hour", hour+":"+minute+" "+am_pm);
}
setInterval(date_time,500);
This is exactly what i wanted, thank you so much :D Have a great week!
Hey Daniel (or any Javascript experts out there).
That script just there is perfect and it works beautifully for my interface demo which will show the user's current time as they interact with the module.
However, I have a request to show time-based information within the display and I was wondering how could this be adjusted to have a variable display, say, 4 minutes earlier than the current time? Like in a text message timeline, for example.
4.36PM: Diarmaid wrote this.
%12Hour%: Diarmaid wrote this.
4.32PM: Diarmaid thought about writing this.
%12Hour_Minus4Mins%: Diarmaid thought about writing this.
I thought I could just use some mathematics but realised that it's a text string variable so I am stumped.
https://360.articulate.com/review/content/6520f497-57b5-4213-9468-ca2fc57f4b9f/review
here the updated script
the time is now minus 4 minutes (in milliseconds)
Jürgen
Thank you so much for the solution Jurgen. That is deeply, deeply appreciated.
If I wanted to use that new script AS WELL as the original, I would obviously have to rename the variable 12Hour to something new, like, 12HourMINUS4, so the only thing I would have to replace in your code would be on line 22,
player.SetVar("12Hour", hour+":"+minute+" "+am_pm);
to
player.SetVar("12HourMINUS4", hour+":"+minute+" "+am_pm);
Would that be correct? :)
I know I am being a pain in the ass here, buuuuuuuut... both code scripts would have to be called on in the relevant slide?
Is there any way the 12Hour value can be calculated, and THEN the new value, 12HourMINUSX, (automatically) derived from that?
The functionname is the same too, so you either need to change that too...or change the function so it sets 2 variables. Assuming you using them on the same trigger. If you use them on 2 separate triggers due to the fact Storyline scope is local ( trigger A has no knowledge about trgger B ) you can do as you plan.
here is the example with 12Hour and 12HourMINUS4 an one slide
(with two trigger and two variables)
https://360.articulate.com/review/content/6520f497-57b5-4213-9468-ca2fc57f4b9f/review
Jürgen