Hello Community, I have a question, what’s better? Coding with functions inside another functions or create functions separately?
Examples:
Inside another function
--Spawn Ball
function spawnBalls:tap ()
ball = display.newImage ( "Ball.png" )
ball:setReferencePoint ( display.CenterReferencePoint )
ball.x = mRandom ( 40, wScreen - 40 )
ball.y = mRandom ( 40, hScreen - 40 )
physics.addBody ( ball, ballObject )
ball.myName = "ball"
ball:addEventListener ( "collision", ball )
--Remove Ball Collision
function ball:collision (e)
if ( e.other.myName == "ball" ) then
e.target:removeSelf ()
e.target = nil
print ( "Removed Ball" )
end
end
end
--Listener
Runtime:addEventListener ( "tap", spawnBalls )
Separate
[code]
–Spawn Circles
function spawnCircles ()
local circle = display.newImage ( “GreenBall.png” )
circle:setReferencePoint ( display.CenterReferencePoint )
circle.x = mRandom ( 50, wScreen - 50 )
circle.y = mRandom ( 50, hScreen - 100 )
screenCircles = screenCircles + 1
circle:addEventListener ( “tap”, removeCircles )
–Call Start Game Function
startGame ()
end
–Remove Circles
function removeCircles (e)
if ( gameReady == true ) then
media.playEventSound ( tapSound )
e.target:removeSelf ()
screenCircles = screenCircles - 1
–Getting Status Game
statusGame ()
return true
end
end [import]uid: 81091 topic_id: 18033 reply_id: 318033[/import]


