Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

error in string base class

edited February 2013 in Bugs Posts: 58

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

-- spazzing ball

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

function draw()
    if #ball.tweens == 0 then
    background(40, 40, 50)
    ellipse(ball.x, ball.y, ball.size)

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})
    tween.path(ball, 2 * #ball.tweens, ball.tweens, tween.easing.linear)

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}

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?



  • edited February 2013 Posts: 2,161

    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.

  • Posts: 489

    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.

  • Posts: 58

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

  • Posts: 58

    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?

  • Posts: 489

    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.

  • Posts: 58

    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.

  • SimeonSimeon Admin Mod
    Posts: 5,387

    .@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.

Sign In or Register to comment.