Skip to main content
1-Visitor
May 15, 2019
Solved

Play sequence while value is zero

  • May 15, 2019
  • 1 reply
  • 2594 views

Hello,

 

is it possible to write a JS code to play a sequence while one of the value from thingworx is 0, and stop it if value is changed to 1. Imagine a propeller which should rotate while value is not changed.

 

Many Thanks

Janos

Best answer by tmccombie

How do you plan to initiate the sequence? From a button, or on model load? 

 

I set my experience up to have a button click event start the sequence. Then I call repeatSequence(); on the model PlayStopped event. This will run the sequence until the value you are watching changes. 

 

$scope.stopSequence = function() {
 $scope.app.fn.triggerWidgetService('model-1', 'stop');
};

$scope.repeatSequence = function(){
 var twxvalue = $scope.app.params.TWXvalue;
 if (twxvalue == 0)
 {
 $scope.app.fn.triggerWidgetService('model-1', 'play');
 }
}

 $scope.$watch("app.params.TWXvalue", function sequenceUpdate() {
 console.log('in sequenceUpdate');
 $scope.stopSequence();
 });

1 reply

Janos19871-VisitorAuthor
1-Visitor
May 15, 2019

Let me add one extension to avoid misunderstanding. I would like to repeat a sequence still a value is 0. if value changed sequence should be stop or play other sequence (stopped stage).

 

Thanks

21-Topaz I
May 16, 2019

Yes, you can do that. 

 

Create an application parameter and tie it to the TWX value you want to watch. I named mine 'TWXvalue'.  Then add the below code to your Home.JS file ensuring that you are using your widget IDs and app parameters. 

 

$scope.stopSequence = function() {
 // can add value checks if needed
 $scope.app.fn.triggerWidgetService('model-1', 'stop');
};

$scope.$watch("app.params.TWXvalue", function sequenceUpdate() {
 $scope.stopSequence();
});

This will stop the current sequence playing on model-1 as soon as the value of 'TWXvalue' changes.

Janos19871-VisitorAuthor
1-Visitor
May 21, 2019

Hi, 

 

thanks for your update, but it is not exactly what I would like to get. I would like to repeat a sequence still one of the value is 0. Maybe with $timeout function it is possible. Could you write an example where a sequence is played in all minutes?

 

Thanks

Janos