error in string base class

I made I program that moves a ball randomly around the screen (I was bored) using tweens.

-- spazzing ball

function setup()
    displayMode(FULLSCREEN)
    ball = {x = WIDTH/2, y = HEIGHT/2, size = 20, color = color(255, 255, 255, 255), tweens = {}}
end

function draw()
    if #ball.tweens == 0 then
        setupTweens()
    end
    background(40, 40, 50)
    strokeWidth(2)
    fill(ball.color)
    ellipse(ball.x, ball.y, ball.size)
end

function setupTweens()
    for i=1, 10 do
        --table.insert(ball.tweens, {x = makeTween(WIDTH), y = makeTween(HEIGHT)})
        table.insert(ball.tweens, {x = 0, y = 0})
    end
    tween.path(ball, 2 * #ball.tweens, ball.tweens, tween.easing.linear)
end

function makeTween(max)
     return math.random(ball.size/2, max - ball.size/2)
    --newY = math.random(ball.size/2, HEIGHT - ball.size/2)
    --return {x = newX, y = newY}
end

When I run the program, however, I get this error message from the string base class:

error: [string “-------------------------------------------…”]:474: bad argument #2 to ‘min’ (number expected, got table)

Any ideas?

You have the first two arguments to the tween.path function the wrong way around. Try:

tween.path(2 * #ball.tweens,ball, ball.tweens, tween.easing.linear)

and I think you get what you want.

(Oh, incidentally, it’s nothing to do with the string base class. The word “string” there means 'The error happened in the file/tab that starts with the string “----------…” ')

@Andrew_Stacey - I’ve had this error as well and only recently under 1.5. Although, none of my tabs/files started with the string “-----------” ?

Maybe the error was caught by the tween library (which itself starts with this string)? Eitherway, I agree it is a bit confusing.

As tween() is written in Lua, off-stage, I think you get a Lua error for the relevant chunk if it happens to fall over.

wow… this a great reminder to check the syntax of my code before I post to the forums!
Thanks @mpilgrem

This time I got another error:

error: [string “-------------------------------------------…”]:501: attempt to index local ‘tw’ (a nil value)

I use multiple tabs, and I dont have over 500 lines of code in a single tab! In addiion, I searched my code for ‘tw’ and came up with no results! Any ideas?

Hello @edat44. The Codea API function tween() is, itself, written in Lua. Think of it as code in a tab that is hidden from you. When you do something to cause tween() to crash, you get an error message telling you what went wrong in that hidden tab.

Is this error that occured a bug with the tween library? If its not, it seems like like there should be an error warning message, saying what I did wrong in my code to cause said error to occur.

.@edat44 I don’t think it’s a bug in the tween library, it looks like you tried to pass a nil value to tween.sequence() — I will try to improve the tween library so that it prints better error messages for misuses like this.