Forum Discussion
ShanteBryan
4 years agoCommunity Member
Add minutes using JavaScript
Hey everyone.
I want to create a trigger that adds minutes whenever it executes. Similar to a button that adds points when clicked.
I tried to put together a code to accomplish that. But I don't know where to go from here.
//Bridge SL + JS
var player = GetPlayer();
//Add time. %Clock% is a text SL variable.
var oldTime = new Date('1970-01-01T10:05:00Z');
var addMinutes = 30;
var elapse = new Date(oldTime.getTime() + addMinutes*60000);
var newTime = (elapse.getUTCHours() % 12 || 12) + ':' + ('0' + (elapse.getUTCMinutes())).slice(-2);
player.SetVar("Clock",newTime);
//Bridge SL + JS
var player = GetPlayer();
//Add time. %Clock% is a text SL variable.
var oldTime = new Date('1970-01-01T10:05:00Z');
var addMinutes = 30;
var elapse = new Date(oldTime.getTime() + addMinutes*60000);
var newTime = elapse.toLocaleTimeString('en-US', {
hour: "numeric",
minute: "2-digit"
});
player.SetVar("Clock",newTime);
Any suggestions are appreciated!
No RepliesBe the first to reply