cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Visit the PTCooler (the community lounge) to get to know your fellow community members and check out some of Dale's Friday Humor posts! X

Translate the entire conversation x

How to show live timer in studio in Label Widget

MA8731174
16-Pearl

How to show live timer in studio in Label Widget

Dear Community,

I want to show the timer in the studio in label widget but it does not get update as you can see my function also below. any idea how to achieve this functionality? when i run some other function then it gets render otherwise not. 

 

Thank you

 

 

 

function startCountdown() {
    var countDownTime = 95 * 60 * 1000;
    
    var x = setInterval(function() {
        // Decrease the time left by 1 second (1000 milliseconds)
        countDownTime -= 1000;

        // Time calculations for minutes and seconds
        var minutes = Math.floor(countDownTime / (1000 * 60));
        var seconds = Math.floor((countDownTime % (1000 * 60)) / 1000);

        // Update the text in the widget
        $scope.view.wdg["overAllTime"].text = minutes + "m " + seconds + "s ";

        // If the countdown is over
        if (countDownTime < 0) {
            clearInterval(x);
            $scope.view.wdg["overAllTime"].text = "TIME UP";

            // Start the countdown again
            startCountdown(); 
        }
    }, 1000);
}

// Start the countdown when the script runs
startCountdown();

 

ACCEPTED SOLUTION

Accepted Solutions

Solution: I am giving time in seconds and bind the count param with text of label and its working perfectly fine. Its showing hh:mm:ss.

 

 $scope.$on("$ionicView.afterEnter", function (event) {
    $scope.startCounter();
});

$scope.countdownTimer = function() {
    if ($scope.app.params.timeLeft > 0) {
        $scope.app.params.timeLeft--;

      var hours = Math.floor($scope.app.params.timeLeft / 3600);
      var minutes = Math.floor(($scope.app.params.timeLeft % 3600) / 60);
      var seconds = $scope.app.params.timeLeft % 60;

// Format the time as HHh MMm SSs
var formattedTime = hours + "h " + (minutes < 10 ? "0" + minutes : minutes) + "m " + (seconds < 10 ? "0" + seconds : seconds) + "s";

        
       
        $scope.view.wdg["overAllDownTimer"].text = formattedTime;
    } else {
       
        $scope.stopCounter();
        $scope.view.wdg["overAllDownTimer"].text = "00h:00m:00s"
       
    }
};

$scope.startCounter = function() {
    
      $scope.app.params.timeLeft = $scope.app.params.timeLimit;
      $scope.intervalPromise = $interval($scope.countdownTimer, 1000);
};

$scope.stopCounter = function() {
    $interval.cancel($scope.intervalPromise);
};

 

 

Documentation : https://support.ptc.com/help/vuforia/studio/en/index.html#page/Studio_Help_Center/IntermediateJSInterval.html

View solution in original post

1 REPLY 1

Solution: I am giving time in seconds and bind the count param with text of label and its working perfectly fine. Its showing hh:mm:ss.

 

 $scope.$on("$ionicView.afterEnter", function (event) {
    $scope.startCounter();
});

$scope.countdownTimer = function() {
    if ($scope.app.params.timeLeft > 0) {
        $scope.app.params.timeLeft--;

      var hours = Math.floor($scope.app.params.timeLeft / 3600);
      var minutes = Math.floor(($scope.app.params.timeLeft % 3600) / 60);
      var seconds = $scope.app.params.timeLeft % 60;

// Format the time as HHh MMm SSs
var formattedTime = hours + "h " + (minutes < 10 ? "0" + minutes : minutes) + "m " + (seconds < 10 ? "0" + seconds : seconds) + "s";

        
       
        $scope.view.wdg["overAllDownTimer"].text = formattedTime;
    } else {
       
        $scope.stopCounter();
        $scope.view.wdg["overAllDownTimer"].text = "00h:00m:00s"
       
    }
};

$scope.startCounter = function() {
    
      $scope.app.params.timeLeft = $scope.app.params.timeLimit;
      $scope.intervalPromise = $interval($scope.countdownTimer, 1000);
};

$scope.stopCounter = function() {
    $interval.cancel($scope.intervalPromise);
};

 

 

Documentation : https://support.ptc.com/help/vuforia/studio/en/index.html#page/Studio_Help_Center/IntermediateJSInterval.html

Announcements
Top Tags