Tween.sequence table [solved]

Hi there,

I’d like to create a table of tweens, and then provide these entries as arguments in tween.sequence. Only, I can’t figure out how to convert a table into arguments for a function, and tween.sequence doesn’t accept tables.

Does anybody know how to do this? Thanks in advance!

Hm, worked my way around it now by assigning callback functions to the next tween in a loop now. However, I would still like to know if it’s possible with tween.sequence and an array :slight_smile:

You can unpack an array into a parameter list with Lua’s unpack() function. Here’s is the example from the tween.sequence() documentation, modified to put the tweens in an array, and unpack the array into an argument list for tween.sequence():


function setup()
    point = {x = 10, y = 10}
    
    tweens = {
        tween(1, point, {x=100}),
        tween(1, point, {x=50}),
        tween(1, point, {y=150}),
    }
    
    tween.sequence(unpack(tweens))
end

function draw()
    background(0)
    ellipse(point.x, point.y, 20)
end

Awesome, that is exactly what I was looking for! This is gonna make things a lot easier.