You probably won’t find much on how local variables work within the Corona documents(though they did make some blog tutorials on it in the past) because it’s more of a Lua language thing.
Basically you got it right. A local variable will not be accessible outside of the function it was declared, unless it is passed via a function. If you declare a variable as local at the top of your Lua file then that variable will not be accessible outside of that Lua file. If you google local variables in corona a few things come up, including blog posts by Corona Labs. Those will go into more depth.
The error message you provided is a kind of hard for me to tell you exactly what is because I can’t tell what the line numbers actually are. It looks like it’s one of your addEventListeners calls is causing the issue. If you read the error it’s telling you there is a problem in your gameListener’s function and probably at line 249. Check out what’s going on there. Maybe it can’t find the functions you are assigning to the listener?
Alright, lastly by passing the ball in i mean your gameListener call would look like:
[lua]
gameListener(“add”, ball)
[/lua]
and your gameListener function would look more like
[lua]
function gameListeners(event, myBall)
if event == “add” then
Runtime:addEventListener( “enterFrame”, testWinLoose )
myBall:addEventListener( “touch”, cueShot )
myBall:addEventListener(“collision”, lineDestroyed)
elseif event == “remove” then
Runtime:removeEventListener( “enterFrame”, testWinLoose )
myBall:removeEventListener( “touch”, cueShot )
myBall:removeEventListener(“collision”, lineDestroyed)
end
end
[/lua]
So instead of just passing “add” as event we would be passing the ball object which we then call myBall inside the function. I would probably hold off on changing your code to that method(if you even bother) until you get a grip on what’s going on with your error messages.