Skip to main content
5-Regular Member
May 31, 2017
Question

JS Timer Event Controlling Model Properties

  • May 31, 2017
  • 3 replies
  • 4527 views

I am attempting to use a simple JS timer function to write values to a variable, which is then bound to the model property "ry"

The idea being, I can click a button to call the function, the the model continuously rotates until the function is cleared.

I created the "counter" parameter and bound it to the "ry" property, as well as defining the click events as their respective functions.

However, the dev console shows that the value is not being stored in "counter" and is not showing as bound to "ry."

My code looks like the below:

$scope.set_timer = function(){

  $scope.app.params['counter'] = 0 ;

  $scope.app.params.time=setInterval(function(){

    $scope.app.params['counter'] ++;

    console.log(counter);

  }

  , 1000);

}

$scope.stop_time = function(){

  $scope.app.params.time = clearInterval(time);

}

---------------------------------------------------------------------------------------------------------

Any help is greatly appreciated.

3 replies

5-Regular Member
June 1, 2017

Hi Alexander Ouellet​,

Is counter a ThingWorx Studio Application Parameter?

If yes; try using: $scope.app.params.counter


​I hope it helps.

aouellet5-Regular MemberAuthor
5-Regular Member
June 1, 2017

It is, however I got an error in the console when using .counter vs ['counter']

5-Regular Member
June 1, 2017

In your code, to access the application parameter you don't need to put the variable in the square bracket. use $scope.app.params.counter =0;

I was using the below code:

$scope.start = function(){

  $scope.app.params.counter = 0;

  $scope.countdown = function(){

  $scope.app.params.counter++;

   };

  $scope.intervalPromise = $interval($scope.countdown, 1000, 10);

};

aouellet5-Regular MemberAuthor
5-Regular Member
June 1, 2017

Using simply .counter vs ['counter'] gave an error in the console

aouellet5-Regular MemberAuthor
5-Regular Member
June 1, 2017

Updates:

The function does appear to write to the ry property, but only if I click the model. Any idea why I would have to click to initiate the property update?

Additionally, the values of "counter' still do not appear to be stored in the console, despite clearly being updated. Any thoughts on why that might be?

5-Regular Member
June 2, 2017

Alexander Ouellet​,

On what event are you calling your function?

I have a project where I am updating Application parameters on load of 3D model and it is working fine.

aouellet5-Regular MemberAuthor
5-Regular Member
June 7, 2017

I call the function on a button event.

However, the model doesn't actually update via the parameter unless it is clicked on. i.e. the function is writing the parameter bound to ry, but the model doesn't change to represent those updates unless clicked on.