adding eventListener from an external function

well I have a class called: functions.lua
 
and there i put all my functions
 
now i want to make the ball - (player) move
 
so did:
 
local functions = require(“functions”)
 
then I added the event listener like this:
 
ball:addEventListener(“touch”,functions.moveBall)
 
and i get this error
 
 
 
stack traceback:

    [C]: ?

    [C]: in function 'assert’

    ?: in function 'getOrCreateTable’

    ?: in function 'addEventListener’

    ?: in function 'addEventListener’

    …rs/erezcsillag/Documents/ballGameCORONA/levelone.lua:122: in function <…rs/erezcsillag/Documents/ballGameCORONA/levelone.lua:121>

    ?: in function 'dispatchEvent’

    ?: in function <?:1076>

    (tail call): ?

    ?: in function <?:172>

    ?: in function <?:218>

please help me out!!

**UP**

Sounds like your function is either local or you did not assign it to an object called ‘functions’. Just doing ‘require(“functions”)’ will not assign your function to an object called ‘functions’ - you can just call it.

Post your actual code and I’ll correct it for you.

ok.

--------levelone-------

display.setStatusBar(display.HiddenStatusBar) local storyboard = require ("storyboard") local functions = require ("functions") local scene = storyboard.newScene() local physics = require("physics") physics.start() local bg local ball local ps1 local ps2 local platform local winFlag local winningFloor local floor local rWall local lWall local ceiling local ballBounce = 1.3 local physicsData = (require "flag").physicsData(scaleFactor) --== ------------[CREATESCENE]----------- ==-- function scene:createScene(event) &nbsp; &nbsp;&nbsp; &nbsp; local screenGroup = self.view &nbsp; &nbsp; bg = display.newImage("game/bg.png") &nbsp; &nbsp; screenGroup:insert(bg) &nbsp; &nbsp; ball = display.newImage("game/ball.png") &nbsp; &nbsp; screenGroup:insert(ball) &nbsp; &nbsp; winFlag = display.newImage("game/flag.png") &nbsp; &nbsp; screenGroup:insert(winFlag) &nbsp; &nbsp; platform = display.newImage("game/platform\_normal.png") &nbsp; &nbsp; screenGroup:insert(platform) &nbsp; &nbsp; ps1 = display.newImage("game/platform\_small.png") &nbsp; &nbsp; screenGroup:insert(ps1) &nbsp; &nbsp; ps2 = display.newImage("game/platform\_small.png") &nbsp; &nbsp; screenGroup:insert(ps2) &nbsp; &nbsp; winningFloor = display.newImage("game/floor.png") &nbsp; &nbsp; screenGroup:insert(winningFloor) &nbsp; &nbsp; floor = display.newImage("game/invisbleWall1.png") &nbsp; &nbsp; screenGroup:insert(floor) &nbsp; &nbsp; lWall = display.newImage("game/invisbleWall2.png") &nbsp; &nbsp; screenGroup:insert(lWall) &nbsp; &nbsp; rWall = display.newImage("game/invisbleWall2.png") &nbsp; &nbsp; screenGroup:insert(rWall) &nbsp; &nbsp; ceiling = display.newImage("game/invisbleWall1.png") &nbsp; &nbsp; screenGroup:insert(ceiling) &nbsp; &nbsp;&nbsp; floor.type = "walls" lWall.type = "walls" rWall.type = "walls" ceiling.type = "walls" floor.y = 356 ceiling.y = -37 rWall.x = 517 lWall.x = -36 physics.addBody(floor,"static") physics.addBody(ceiling,"static") physics.addBody(rWall,"static") physics.addBody(lWall,"static") local gameIsOver = false local rotateSpeed = 3.5 local rotateSpeedHole = 10 local ballBounce = 0.6&nbsp; local platformFirstScale = 0.9 winningFloor:setReferencePoint(display.CenterReferencePoint) winningFloor.x = 420 winningFloor.y = 296 physics.addBody(winningFloor,"static") winFlag:setReferencePoint(display.CenterReferencePoint) winFlag.x = 420 winFlag.y = 260 winFlag.xScale = 0.7 winFlag.yScale = 0.7 winFlag.type = "win" physics.addBody( winFlag, "static",physicsData:get("flag") ) platform:setReferencePoint(display.CenterReferencePoint) platform.x = 108 platform.y = 40 platform.xScale = platformFirstScale platform.yScale = platformFirstScale physics.addBody( platform, "static", { friction=0.5, bounce=0.3 } ) ps1:setReferencePoint(display.CenterReferencePoint) ps1.x = 60 ps1.y = 20 ps1.xScale = platformFirstScale ps1.yScale = platformFirstScale physics.addBody( ps1, "static", { friction=0.5, bounce=0.3 } ) ps2:setReferencePoint(display.CenterReferencePoint) ps2.x = 155 ps2.y = 20 ps2.xScale = platformFirstScale ps2.yScale = platformFirstScale physics.addBody( ps2, "static", { friction=0.5, bounce=0.3 } ) ball:setReferencePoint(display.CenterReferencePoint) ball.x = 50 ball.y = 90 ball.xScale = 0.14 ball.yScale = 0.14 ball.type = "ball" end --== ----------[ENTERSCENE]---------- ==-- function scene:enterScene(event) &nbsp; ball:addEventListener("touch", functions.startPhysics) &nbsp; &nbsp; platform:addEventListener("touch", functions.startDrag) &nbsp; ps1:addEventListener("touch", functions.startDrag) &nbsp; ps2:addEventListener("touch", functions.startDrag) &nbsp; ball.collision = functions.ballCollision &nbsp; ball:addEventListener("collision", ball)&nbsp; end --== ----------[EXITSCENE]---------- ==-- function scene:exitScene(event) end --== ----------[DESTROYSCENE]---------- ==-- function scene:destroyScene(event) &nbsp; end -------------------[EVENTLISTENERS]---------------- &nbsp; scene:addEventListener( "createScene", scene ) &nbsp; scene:addEventListener( "enterScene", scene ) &nbsp; scene:addEventListener( "exitScene", scene ) &nbsp; scene:addEventListener( "destroyScene", scene ) &nbsp; return scene &nbsp;

-----------functions------

local function startDrag(event) &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local t = event.target &nbsp; &nbsp; &nbsp; &nbsp; local phase = event.phase &nbsp; &nbsp; &nbsp; &nbsp; if "began" == phase then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( t ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Store initial position &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x0 = event.x - t.x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y0 = event.y - t.y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t = transition.to( t, { xScale=1, yScale=1} ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Make body type temporarily "kinematic" (to avoid gravitional forces) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.target.bodyType = "kinematic" &nbsp; &nbsp; &nbsp; &nbsp; elseif t.isFocus then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if "moved" == phase then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x = event.x - t.x0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y = event.y - t.y0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif "ended" == phase then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( nil ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:removeEventListener("touch",startDrag) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:addEventListener("touch",rotatePlatform) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; -- Stop further propagation of touch event! &nbsp; &nbsp; &nbsp; &nbsp; return true end &nbsp; &nbsp; local function rotatePlatform(event) &nbsp; &nbsp; &nbsp; &nbsp; local t = event.target &nbsp; &nbsp; &nbsp; &nbsp; local phase = event.phase &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (phase == "began") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( t ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Store initial position of finger &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x1 = event.x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y1 = event.y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif t.isFocus then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (phase == "moved") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x2 = event.x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y2 = event.y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle1 = 180/math.pi \* math.atan2(t.y1 - t.y , t.x1 - t.x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle2 = 180/math.pi \* math.atan2(t.y2 - t.y , t.x2 - t.x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("angle1 = "..angle1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rotationAmt = angle1 - angle2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --rotate it &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.rotation = t.rotation - rotationAmt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ("t.rotation = "..t.rotation) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x1 = t.x2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y1 = t.y2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif (phase == "ended") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:addEventListener("touch", startDrag) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( nil ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return true end local function gameOver(event) &nbsp; &nbsp; storyboard.gotoScene("levelselect", "fade", 700) &nbsp; &nbsp; print("gameover") end local function ballCollision(self,event) &nbsp; if event.phase == "began" then &nbsp; &nbsp; rotateSpeed = 0 &nbsp; &nbsp; if(event.target.type == "ball" and event.other.type == "walls") then &nbsp; &nbsp; &nbsp; gameOver() &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; if event.target.type == "ball" and event.other.type == "win" then &nbsp; &nbsp; &nbsp; levelComplete() &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if event.phase == "moved" then &nbsp; &nbsp; &nbsp; rotateSpeed = 3.5 &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if event.phase == "ended" then &nbsp; &nbsp; &nbsp; rotateSpeed = 3.5 &nbsp; &nbsp; &nbsp; end &nbsp; end &nbsp;&nbsp; local function levelComplete(event) &nbsp; &nbsp; ball:setLinearVelocity(0,0) &nbsp; &nbsp; storyboard.gotoScene("levelselect","fade",700) &nbsp; &nbsp; print("levelCompleted") &nbsp; &nbsp; end &nbsp; &nbsp; local function startPhysics(event) &nbsp; local phase = event.phase &nbsp; local t = event.target &nbsp; if phase == "began" then &nbsp; &nbsp; platform:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; platform:removeEventListener("touch", startDrag) &nbsp; &nbsp; ps1:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; &nbsp; ps1:removeEventListener("touch", startDrag) &nbsp; &nbsp; ps2:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; ps2:removeEventListener("touch", startDrag) &nbsp; &nbsp; physics.addBody(t,{bounce = ballBounce ,radius = 18}) &nbsp; end &nbsp; end &nbsp;&nbsp; &nbsp; local allFun = { &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;startPhysics, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;levelComplete, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;rotatePlatform, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;startDrag, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;gameOver, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ballCollision &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp; &nbsp; return allFun &nbsp;

Your functions class returns a table containing the functions, but they are not named, they are numerically indexed. If you loop through the table

for i=1, #functions do print(functions[i]) end

You will see a list of functions, but they have no names. The easiest way to call them by name is to change your functions in the functions.lua to declare each function like this:

allFun.startPhysics = function( event )

And move your allFun to the top of the file like this:

local allFun = {}

thanks

**UP**

Sounds like your function is either local or you did not assign it to an object called ‘functions’. Just doing ‘require(“functions”)’ will not assign your function to an object called ‘functions’ - you can just call it.

Post your actual code and I’ll correct it for you.

ok.

--------levelone-------

display.setStatusBar(display.HiddenStatusBar) local storyboard = require ("storyboard") local functions = require ("functions") local scene = storyboard.newScene() local physics = require("physics") physics.start() local bg local ball local ps1 local ps2 local platform local winFlag local winningFloor local floor local rWall local lWall local ceiling local ballBounce = 1.3 local physicsData = (require "flag").physicsData(scaleFactor) --== ------------[CREATESCENE]----------- ==-- function scene:createScene(event) &nbsp; &nbsp;&nbsp; &nbsp; local screenGroup = self.view &nbsp; &nbsp; bg = display.newImage("game/bg.png") &nbsp; &nbsp; screenGroup:insert(bg) &nbsp; &nbsp; ball = display.newImage("game/ball.png") &nbsp; &nbsp; screenGroup:insert(ball) &nbsp; &nbsp; winFlag = display.newImage("game/flag.png") &nbsp; &nbsp; screenGroup:insert(winFlag) &nbsp; &nbsp; platform = display.newImage("game/platform\_normal.png") &nbsp; &nbsp; screenGroup:insert(platform) &nbsp; &nbsp; ps1 = display.newImage("game/platform\_small.png") &nbsp; &nbsp; screenGroup:insert(ps1) &nbsp; &nbsp; ps2 = display.newImage("game/platform\_small.png") &nbsp; &nbsp; screenGroup:insert(ps2) &nbsp; &nbsp; winningFloor = display.newImage("game/floor.png") &nbsp; &nbsp; screenGroup:insert(winningFloor) &nbsp; &nbsp; floor = display.newImage("game/invisbleWall1.png") &nbsp; &nbsp; screenGroup:insert(floor) &nbsp; &nbsp; lWall = display.newImage("game/invisbleWall2.png") &nbsp; &nbsp; screenGroup:insert(lWall) &nbsp; &nbsp; rWall = display.newImage("game/invisbleWall2.png") &nbsp; &nbsp; screenGroup:insert(rWall) &nbsp; &nbsp; ceiling = display.newImage("game/invisbleWall1.png") &nbsp; &nbsp; screenGroup:insert(ceiling) &nbsp; &nbsp;&nbsp; floor.type = "walls" lWall.type = "walls" rWall.type = "walls" ceiling.type = "walls" floor.y = 356 ceiling.y = -37 rWall.x = 517 lWall.x = -36 physics.addBody(floor,"static") physics.addBody(ceiling,"static") physics.addBody(rWall,"static") physics.addBody(lWall,"static") local gameIsOver = false local rotateSpeed = 3.5 local rotateSpeedHole = 10 local ballBounce = 0.6&nbsp; local platformFirstScale = 0.9 winningFloor:setReferencePoint(display.CenterReferencePoint) winningFloor.x = 420 winningFloor.y = 296 physics.addBody(winningFloor,"static") winFlag:setReferencePoint(display.CenterReferencePoint) winFlag.x = 420 winFlag.y = 260 winFlag.xScale = 0.7 winFlag.yScale = 0.7 winFlag.type = "win" physics.addBody( winFlag, "static",physicsData:get("flag") ) platform:setReferencePoint(display.CenterReferencePoint) platform.x = 108 platform.y = 40 platform.xScale = platformFirstScale platform.yScale = platformFirstScale physics.addBody( platform, "static", { friction=0.5, bounce=0.3 } ) ps1:setReferencePoint(display.CenterReferencePoint) ps1.x = 60 ps1.y = 20 ps1.xScale = platformFirstScale ps1.yScale = platformFirstScale physics.addBody( ps1, "static", { friction=0.5, bounce=0.3 } ) ps2:setReferencePoint(display.CenterReferencePoint) ps2.x = 155 ps2.y = 20 ps2.xScale = platformFirstScale ps2.yScale = platformFirstScale physics.addBody( ps2, "static", { friction=0.5, bounce=0.3 } ) ball:setReferencePoint(display.CenterReferencePoint) ball.x = 50 ball.y = 90 ball.xScale = 0.14 ball.yScale = 0.14 ball.type = "ball" end --== ----------[ENTERSCENE]---------- ==-- function scene:enterScene(event) &nbsp; ball:addEventListener("touch", functions.startPhysics) &nbsp; &nbsp; platform:addEventListener("touch", functions.startDrag) &nbsp; ps1:addEventListener("touch", functions.startDrag) &nbsp; ps2:addEventListener("touch", functions.startDrag) &nbsp; ball.collision = functions.ballCollision &nbsp; ball:addEventListener("collision", ball)&nbsp; end --== ----------[EXITSCENE]---------- ==-- function scene:exitScene(event) end --== ----------[DESTROYSCENE]---------- ==-- function scene:destroyScene(event) &nbsp; end -------------------[EVENTLISTENERS]---------------- &nbsp; scene:addEventListener( "createScene", scene ) &nbsp; scene:addEventListener( "enterScene", scene ) &nbsp; scene:addEventListener( "exitScene", scene ) &nbsp; scene:addEventListener( "destroyScene", scene ) &nbsp; return scene &nbsp;

-----------functions------

local function startDrag(event) &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; local t = event.target &nbsp; &nbsp; &nbsp; &nbsp; local phase = event.phase &nbsp; &nbsp; &nbsp; &nbsp; if "began" == phase then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( t ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Store initial position &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x0 = event.x - t.x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y0 = event.y - t.y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t = transition.to( t, { xScale=1, yScale=1} ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Make body type temporarily "kinematic" (to avoid gravitional forces) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; event.target.bodyType = "kinematic" &nbsp; &nbsp; &nbsp; &nbsp; elseif t.isFocus then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if "moved" == phase then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x = event.x - t.x0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y = event.y - t.y0 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif "ended" == phase then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( nil ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:removeEventListener("touch",startDrag) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:addEventListener("touch",rotatePlatform) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; -- Stop further propagation of touch event! &nbsp; &nbsp; &nbsp; &nbsp; return true end &nbsp; &nbsp; local function rotatePlatform(event) &nbsp; &nbsp; &nbsp; &nbsp; local t = event.target &nbsp; &nbsp; &nbsp; &nbsp; local phase = event.phase &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (phase == "began") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( t ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = true &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; -- Store initial position of finger &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x1 = event.x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y1 = event.y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif t.isFocus then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (phase == "moved") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x2 = event.x &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y2 = event.y &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle1 = 180/math.pi \* math.atan2(t.y1 - t.y , t.x1 - t.x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; angle2 = 180/math.pi \* math.atan2(t.y2 - t.y , t.x2 - t.x) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print("angle1 = "..angle1) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rotationAmt = angle1 - angle2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; --rotate it &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.rotation = t.rotation - rotationAmt &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; print ("t.rotation = "..t.rotation) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.x1 = t.x2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.y1 = t.y2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elseif (phase == "ended") then &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:addEventListener("touch", startDrag) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; display.getCurrentStage():setFocus( nil ) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t.isFocus = false &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; t:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; &nbsp; &nbsp; return true end local function gameOver(event) &nbsp; &nbsp; storyboard.gotoScene("levelselect", "fade", 700) &nbsp; &nbsp; print("gameover") end local function ballCollision(self,event) &nbsp; if event.phase == "began" then &nbsp; &nbsp; rotateSpeed = 0 &nbsp; &nbsp; if(event.target.type == "ball" and event.other.type == "walls") then &nbsp; &nbsp; &nbsp; gameOver() &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; if event.target.type == "ball" and event.other.type == "win" then &nbsp; &nbsp; &nbsp; levelComplete() &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if event.phase == "moved" then &nbsp; &nbsp; &nbsp; rotateSpeed = 3.5 &nbsp; &nbsp; &nbsp; end &nbsp; &nbsp;&nbsp; &nbsp; &nbsp; if event.phase == "ended" then &nbsp; &nbsp; &nbsp; rotateSpeed = 3.5 &nbsp; &nbsp; &nbsp; end &nbsp; end &nbsp;&nbsp; local function levelComplete(event) &nbsp; &nbsp; ball:setLinearVelocity(0,0) &nbsp; &nbsp; storyboard.gotoScene("levelselect","fade",700) &nbsp; &nbsp; print("levelCompleted") &nbsp; &nbsp; end &nbsp; &nbsp; local function startPhysics(event) &nbsp; local phase = event.phase &nbsp; local t = event.target &nbsp; if phase == "began" then &nbsp; &nbsp; platform:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; platform:removeEventListener("touch", startDrag) &nbsp; &nbsp; ps1:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; &nbsp; ps1:removeEventListener("touch", startDrag) &nbsp; &nbsp; ps2:removeEventListener("touch", rotatePlatform) &nbsp; &nbsp; ps2:removeEventListener("touch", startDrag) &nbsp; &nbsp; physics.addBody(t,{bounce = ballBounce ,radius = 18}) &nbsp; end &nbsp; end &nbsp;&nbsp; &nbsp; local allFun = { &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;startPhysics, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;levelComplete, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;rotatePlatform, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;startDrag, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;gameOver, &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;ballCollision &nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;} &nbsp;&nbsp; &nbsp; return allFun &nbsp;

Your functions class returns a table containing the functions, but they are not named, they are numerically indexed. If you loop through the table

for i=1, #functions do print(functions[i]) end

You will see a list of functions, but they have no names. The easiest way to call them by name is to change your functions in the functions.lua to declare each function like this:

allFun.startPhysics = function( event )

And move your allFun to the top of the file like this:

local allFun = {}

thanks