Tween sequence issue

The mystery deepens…

@epicurus101, @Jmv38,@yojimbo2000 -

Actually, the problem seems to be the opposite, as you can see if you change my code to this

function setup()
    c={b=0} --<-- b instead of d (throughout the code)
    t1=tween( 3, a, { b=200 }, tween.easing.quadInOut )
    t2=tween( 3, c, { b=200 }, tween.easing.quadInOut )

function draw()

When the tween targets are different, but the tweened item has the same name, it doesn’t work properly.

@Ignatz Haha, I was trying all sorts of ways to break your code, but couldn’t. Well, I think you have solved it. Pretty weird behaviour though. It seems that Codea’s tween API forked this , so we can see how easing works, but it would be useful to be able to see how things like sequence and looping work. Of course I can understand why the developers wouldn’t want to open source bits of their APIs

When the 2 Tweens are created, their initial values are set at the point of creation in setup(). When tween t1 runs, the variable ‘b’ goes from 0 to 200 over a period of 3 seconds. When tween t2 runs, the variable ‘b’ doesn’t get set back to 0 because it was set to 0 in setup and that doesn’t get run again. Since ‘b’ is sitting at 200 from the ‘t1’ run, that’s the value tween ‘t2’ sees it at.

I don’t think that’s the problem, because the tweens are supposed to store the table addresses and item names. If this is done correctly, the two b’s above will be correctly recognised as belonging to different tables.

Somehow, tween is getting confused and thinking the second b is the same as the first.

I think we have enough to file a bug report.

@Simeon if you run the two code samples immediately above, you’ll see the problem with the second one.

And if you feel like decoding, @dave1707, John’s tween code, including tween sequence, appears to be here in draft form

(But I’m going to bed. It’s late in Australia!)

@Ignatz thanks for that link, I hadn’t seen that before. It’s interesting that looping used to be implemented differently, with a tween.loop function that you call the same way as tween.sequence. It looks like you used to be able to specify how many times it repeated too, making my tween.loopN function above redundant. If I have time, I’ll see if I can add the old version of tween.loop to a project

Hi all. I had the same problem with some code of mine. I wanted to change the opacity of some text on screen with a simple fade in from 0 to 100% then a delay then a fade out back to 0%.

This wasted sooooo much of my time. I should have searched for this discussion first but in a way it was good I sussed it on my own. I ended up avoiding sequences, which appears broken on the face of it. I simple nested the call backs which is confusing to read but is OK for short sequences. I like tweens in general but it has rough edges like this sometimes

My own resolved code:

tween(0.5, self, {opacity=100}, tween.easing.linear, function() tween.delay(2, function() tween(0.5, self, {opacity=0}, tween.easing.linear, function() last_callback end) end) end)

If you’re not happy with Tween callback functions, you can roll your own by taking advantage of the running and time variable that each tween has. When a tween has ended, running will be >= to time:

if self.tween and self.tweenAction and self.tween.running>=self.tween.time then

where self.tween is the id of the tween, and self.tweenAction is a function that is part of the class

@todddixon Here’s some code to cause text to fade in for 3 seconds, show for 3 seconds, then 3 seconds to fade out. Tap screen to start sequence.


function setup()

function draw()
    text("tap scren for",WIDTH/2,HEIGHT-200)
    text("3 sec fade in, 3 sec show, 3 sec fade out",WIDTH/2,HEIGHT-250)
    text("Show some text to fade in fade out",WIDTH/2,HEIGHT/2)

function touched(t)
    if t.state==BEGAN then