Repeating tween chain

Very much related to my post: Chaining tween.rotate. As I mention in this post, I have figured out how to chain tweens to make an object rotate fully around an axis. tween.chain(tween1, tween2, tween3) cycles through all of the tweens until it comes to rest at it’s original position. Adding tween1 back to the end of the chain creates the loop method with the full chain: tween.chain(tween1, tween2, tween3, tween1). This of course means the chain just endlessly loops, which is great, but I need a way to make this into the repeat method, so I can control how many times the chain loops. Any ideas?

EDIT: I don’t mention this in the other post, so I thought I should here. Adding .repeat(x) to the end of the chain only repeats the first tween x times, not the entire chain.

@BenBean303 you’ve been able to help me figure out most of this, any ideas here? I’ve been using a timer to act as my stop, but it’s prone to causing problems.

Can you put some countdown logic in the “completed” event for the last tween in the chain?

Example dragged from some code I’m using.

       .tween(this.entity.getLocalPosition()).to({x: 45, y: 1000, z: 1}, duration, pc.SineOut)
       .on('update', function(){ = true; })
       .on('complete', function(){ 
              // logic in here to stop the chain

Can you explain what you mean by this? As it is I have the tween chain set to run until a timer hits a certain number, then that gets stopped wherever it may be in the chain and another tween meant to go to the final position starts. The timer does cause some issues, as sometimes when it ends, the shortest way to tween to the last point is to reverse the rotation and the logic I’m using to fix this is getting quite complicated. I also have another version of this project that tracks how many times the object rotates based on when it rotates past the starting rotation value, give or take a few points (if start is 25, it counts as a rotation when the value is between 23-27). The problem with this is the update function sometimes doesn’t check fast enough, so the wheel will rotate around 2 or 3 times before the count increases.

If there is a way to get the full chain of tweens to repeat a set number of times, getting the final tween to work will be easy compared how it I’m doing it now.