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)
(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 “----------…” ')
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.