Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
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
Solved! Go to Solution.
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(); });
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
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.
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
Could anyone help me in this case? I would like to repeat a sequence still a value changed.
Thanks
Janos
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(); });
perfect, thanks
Janos