horacebury:
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) local screenGroup = self.view bg = display.newImage("game/bg.png") screenGroup:insert(bg) ball = display.newImage("game/ball.png") screenGroup:insert(ball) winFlag = display.newImage("game/flag.png") screenGroup:insert(winFlag) platform = display.newImage("game/platform\_normal.png") screenGroup:insert(platform) ps1 = display.newImage("game/platform\_small.png") screenGroup:insert(ps1) ps2 = display.newImage("game/platform\_small.png") screenGroup:insert(ps2) winningFloor = display.newImage("game/floor.png") screenGroup:insert(winningFloor) floor = display.newImage("game/invisbleWall1.png") screenGroup:insert(floor) lWall = display.newImage("game/invisbleWall2.png") screenGroup:insert(lWall) rWall = display.newImage("game/invisbleWall2.png") screenGroup:insert(rWall) ceiling = display.newImage("game/invisbleWall1.png") screenGroup:insert(ceiling) 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 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) ball:addEventListener("touch", functions.startPhysics) platform:addEventListener("touch", functions.startDrag) ps1:addEventListener("touch", functions.startDrag) ps2:addEventListener("touch", functions.startDrag) ball.collision = functions.ballCollision ball:addEventListener("collision", ball) end --== ----------[EXITSCENE]---------- ==-- function scene:exitScene(event) end --== ----------[DESTROYSCENE]---------- ==-- function scene:destroyScene(event) end -------------------[EVENTLISTENERS]---------------- scene:addEventListener( "createScene", scene ) scene:addEventListener( "enterScene", scene ) scene:addEventListener( "exitScene", scene ) scene:addEventListener( "destroyScene", scene ) return scene
-----------functions------
local function startDrag(event) local t = event.target local phase = event.phase if "began" == phase then t:removeEventListener("touch", rotatePlatform) display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position t.x0 = event.x - t.x t.y0 = event.y - t.y t = transition.to( t, { xScale=1, yScale=1} ) -- Make body type temporarily "kinematic" (to avoid gravitional forces) event.target.bodyType = "kinematic" elseif t.isFocus then if "moved" == phase then t.x = event.x - t.x0 t.y = event.y - t.y0 elseif "ended" == phase then display.getCurrentStage():setFocus( nil ) t.isFocus = false t:removeEventListener("touch",startDrag) t:addEventListener("touch",rotatePlatform) end end -- Stop further propagation of touch event! return true end local function rotatePlatform(event) local t = event.target local phase = event.phase if (phase == "began") then display.getCurrentStage():setFocus( t ) t.isFocus = true -- Store initial position of finger t.x1 = event.x t.y1 = event.y elseif t.isFocus then if (phase == "moved") then t.x2 = event.x t.y2 = event.y angle1 = 180/math.pi \* math.atan2(t.y1 - t.y , t.x1 - t.x) angle2 = 180/math.pi \* math.atan2(t.y2 - t.y , t.x2 - t.x) print("angle1 = "..angle1) rotationAmt = angle1 - angle2 --rotate it t.rotation = t.rotation - rotationAmt print ("t.rotation = "..t.rotation) t.x1 = t.x2 t.y1 = t.y2 elseif (phase == "ended") then t:addEventListener("touch", startDrag) display.getCurrentStage():setFocus( nil ) t.isFocus = false t:removeEventListener("touch", rotatePlatform) end end return true end local function gameOver(event) storyboard.gotoScene("levelselect", "fade", 700) print("gameover") end local function ballCollision(self,event) if event.phase == "began" then rotateSpeed = 0 if(event.target.type == "ball" and event.other.type == "walls") then gameOver() end if event.target.type == "ball" and event.other.type == "win" then levelComplete() end end if event.phase == "moved" then rotateSpeed = 3.5 end if event.phase == "ended" then rotateSpeed = 3.5 end end local function levelComplete(event) ball:setLinearVelocity(0,0) storyboard.gotoScene("levelselect","fade",700) print("levelCompleted") end local function startPhysics(event) local phase = event.phase local t = event.target if phase == "began" then platform:removeEventListener("touch", rotatePlatform) platform:removeEventListener("touch", startDrag) ps1:removeEventListener("touch", rotatePlatform) ps1:removeEventListener("touch", startDrag) ps2:removeEventListener("touch", rotatePlatform) ps2:removeEventListener("touch", startDrag) physics.addBody(t,{bounce = ballBounce ,radius = 18}) end end local allFun = { startPhysics, levelComplete, rotatePlatform, startDrag, gameOver, ballCollision } return allFun