dispatchEvent error in storyboard - lua

When i pressed the credits button from the menu it gave me an error "?:0: attempt to call method 'dispatchEvent' (a nil value) ?:in function 'gotoScene'...scene_menu.lua:35: in function ...scene_menu.lua:33>?:in function "...Whats the problem here?
This is my menu page
-- scene_menu.lua
local storyboard = require( "storyboard" )
local scene = storyboard.newScene()
-- Clear previous scene
storyboard.removeAll()
--forward references
local background
local title
local playGame
local tutorial
local credits
display.setStatusBar(display.HiddenStatusBar)
function playgameBtn( event )
transition.to(playGame, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("playgame", "fade", 1000)
end
function tutorialBtn (event)
transition.to(tutorial, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("tutorial", "fade", 1000)
end
function creditsBtn (event)
transition.to(credits, {time = 1000, alpha = 0, xScale = 2, yScale = .6})
storyboard.gotoScene("credits", "fade", 1000)
end
function scene:createScene(event)
local group = self.view
background = display.newImage( "bkg_clouds.png")
group:insert(background)
background.x = 240
background.y = 195
title = display.newText("Shoot the Balloons!", 250, 100, native.systemFont, 25 )
title:setFillColor( 1,1, 0 )
playgame = display.newImage("Play Button.png")
group:insert(playgame)
playgame.x = 250
playgame.y = 150
tutorial = display.newImage("Tutorial Button.png")
group:insert(tutorial)
tutorial.x = 250
tutorial.y = 200
credits = display.newImage("Credits Button.png")
group:insert(credits)
credits.x = 250
credits.y = 250
end
function scene:enterScene( event )
playgame:addEventListener("tap", playgameBtn)
tutorial:addEventListener("tap", tutorialBtn)
credits:addEventListener("tap", creditsBtn)
end
function scene:exitScene(event)
playgame:removeEventListener("tap", playgameBtn)
tutorial:removeEventListener("tap", tutorialBtn)
credits:removeEventListener("tap", creditsBtn)
end
function scene:destroyScene(event)
end
scene:addEventListener("createScene", scene)
scene:addEventListener("enterScene", scene)
scene:addEventListener("exitScene", scene)
scene:addEventListener("destroyScene", scene)
return scene
This is my main.lua
-- main.lua
display.setStatusBar( display.HiddenStatusBar )
local storyboard = require "storyboard"
storyboard.gotoScene( "scene_splash" )

change the name credits.lua to the other name or change the variable name credits global variable,i think its due to the conflict of name in this line:storyboard.gotoScene("credits", "fade", 1000)

Related

I got an error here in main.lua: 178: attempt to index global 'pausebutton' (a nil value)

I got an error in Corona's simulator console in main.lua
attempt to index global pausebutton (a nil value)
How to solve my problem with Corona error?
The most revelant code from main.lua file I put below
-- Display the pause button
function pauseAndResume ()
local pausebutton = display.newImage ("pause.png")
pausebutton : translate(100, 100)
pausebutton:addEventListener ("touch" , pauseGame)
local resumebutton = display.newImage ("resumed.png")
resumebutton: translate(100, 100)
resumebutton.isVisible = false
resumebutton:addEventListener ("touch", resumeGame)
end
function pauseGame (event)
if (event.phase == "ended") then
physics.pause ()
pausebutton.isVisible = false
resumebutton.isVisible = true
timer.pause(fruitTimer)
timer.pause(bombTimer)
sampleVar = false
return true
end
end
function resumeGame (event)
if (event.phase == "ended") then
physics.start()
pausebutton.isVisible = true
resumebutton.isVisible = false
timer.resume(fruitTimer)
timer.resume(bombTimer)
sampleVar = true
return true
end
end
I think you got error because local variables pausebutton and resumebutton exist only during executing of pauseAndResume function. After that they gone. So you need declare them in the block in which they will be available for pauseAndResume and pauseGame functions, for example on begining of the main.lua file.
Try
local pausebutton
local resumebutton
...
-- Display the pause button
function pauseAndResume ()
pausebutton = display.newImage ("pause.png")
pausebutton : translate(100, 100)
pausebutton:addEventListener ("touch" , pauseGame)
resumebutton = display.newImage ("resumed.png")
resumebutton: translate(100, 100)
resumebutton.isVisible = false
resumebutton:addEventListener ("touch", resumeGame)
end
function pauseGame (event)
if (event.phase == "ended") then
physics.pause ()
pausebutton.isVisible = false
resumebutton.isVisible = true
timer.pause(fruitTimer)
timer.pause(bombTimer)
sampleVar = false
return true
end
end
function resumeGame (event)
if (event.phase == "ended") then
physics.start()
pausebutton.isVisible = true
resumebutton.isVisible = false
timer.resume(fruitTimer)
timer.resume(bombTimer)
sampleVar = true
return true
end
end
From Lua documentation
We create local variables with the local statement:
j = 10 -- global variable
local i = 1 -- local variable
Unlike global variables, local variables have their scope limited to
the block where they are declared. A block is the body of a control
structure, the body of a function, or a chunk (the file or string with
the code where the variable is declared).
-- Samurai Fruit
require ("physics")
local ui = require("ui")
physics.start()
-- physics.setDrawMode ( "hybrid" ) -- Uncomment in order to show in hybrid mode
physics.setGravity( 0, 9.8 * 2)
physics.start()
-- Audio for slash sound (sound you hear when user swipes his/her finger across the screen)
local slashSounds = {slash1 = audio.loadSound("slash1.wav"), slash2 = audio.loadSound("slash2.wav"), slash3 = audio.loadSound("slash3.wav")}
local slashSoundEnabled = true -- sound should be enabled by default on startup
local minTimeBetweenSlashes = 150 -- Minimum amount of time in between each slash sound
local minDistanceForSlashSound = 50 -- Amount of pixels the users finger needs to travel in one frame in order to play a slash sound
-- Audio for chopped fruit
local choppedSound = {chopped1 = audio.loadSound("chopped1.wav"), chopped2 = audio.loadSound("chopped2.wav")}
-- Audio for bomb
local preExplosion = audio.loadSound("preExplosion.wav")
local explosion = audio.loadSound("explosion.wav")
-- Adding a collision filter so the fruits do not collide with each other, they only collide with the catch platform
local fruitProp = {density = 1.0, friction = 0.3, bounce = 0.2, filter = {categoryBits = 2, maskBits = 1}}
local catchPlatformProp = {density = 1.0, friction = 0.3, bounce = 0.2, filter = {categoryBits = 1, maskBits = 2}}
-- Gush filter should not interact with other fruit or the catch platform
local gushProp = {density = 1.0, friction = 0.3, bounce = 0.2, filter = {categoryBits = 4, maskBits = 8} }
-- Will contain all fruits available in the game
local avalFruit = {}
-- Slash line properties (line that shows up when you move finger across the screen)
local maxPoints = 5
local lineThickness = 20
local lineFadeTime = 250
local endPoints = {}
-- Whole Fruit physics properties
local minVelocityY = 850
local maxVelocityY = 1100
local minVelocityX = -200
local maxVelocityX = 200
local minAngularVelocity = 100
local maxAngularVelocity = 200
-- Chopped fruit physics properties
local minAngularVelocityChopped = 100
local maxAngularVelocityChopped = 200
-- Splash properties
local splashFadeTime = 2500
local splashFadeDelayTime = 5000
local splashInitAlpha = .5
local splashSlideDistance = 50 -- The amoutn of of distance the splash slides down the background
-- Contains all the available splash images
local splashImgs = {}
-- Gush properties
local minGushRadius = 10
local maxGushRadius = 25
local numOfGushParticles = 15
local gushFadeTime = 500
local gushFadeDelay = 500
local minGushVelocityX = -350
local maxGushVelocityX = 350
local minGushVelocityY = -350
local maxGushVelocityY = 350
-- Timer references
local bombTimer
local fruitTimer
-- Game properties
local fruitShootingInterval = 1000
local bombShootingInterval = 5000
-- Groups for holding the fruit and splash objects
local splashGroup
local fruitGroup
local sampleVar = true
local score = 0
local scoreText
function main()
score = 0
display.setStatusBar( display.HiddenStatusBar )
setUpBackground()
scoreText = display.newText("Score: 0", 415, 100, native.systemFont, 50)
scoreText:setTextColor(255, 255, 255)
scoreText.text = ("Score: " )..score
pauseAndResume ()
setUpCatchPlatform()
initGroups()
initFruitAndSplash()
Runtime:addEventListener("touch", drawSlashLine)
timer.performWithDelay( 1000, displayScore)
startGame()
end
function displayScore()
scoreText.text = ("Score: " )..score
score = score + 2
end
function startGame()
shootObject("fruit")
bombTimer = timer.performWithDelay(bombShootingInterval, function(event) shootObject("bomb") end, 0)
fruitTimer = timer.performWithDelay(fruitShootingInterval, function(event) shootObject("fruit") end, 0)
end
-- Display the pause button
function pauseAndResume ()
local pausebutton = display.newImage ("pause.png")
pausebutton : translate(100, 100)
pausebutton:addEventListener ("touch" , pauseGame)
local resumebutton = display.newImage ("resumed.png")
resumebutton: translate(100, 100)
resumebutton.isVisible = false
resumebutton:addEventListener ("touch", resumeGame)
end
function pauseGame (event)
if (event.phase == "ended") then
physics.pause ()
pausebutton.isVisible = false
resumebutton.isVisible = true
timer.pause(fruitTimer)
timer.pause(bombTimer)
sampleVar = false
return true
end
end
function resumeGame (event)
if (event.phase == "ended") then
physics.start()
pausebutton.isVisible = true
resumebutton.isVisible = false
timer.resume(fruitTimer)
timer.resume(bombTimer)
sampleVar = true
return true
end
end
function initGroups()
splashGroup = display.newGroup()
fruitGroup = display.newGroup()
end
function setUpBackground()
local background = display.newImage("bg.png", true)
background.x = display.contentWidth / 2
background.y = display.contentHeight / 2
end
-- Populates avalFruit with all the fruit images and thier widths and heights
function initFruitAndSplash()
local watermelon = {}
watermelon.whole = "watermelonWhole.png"
watermelon.top = "watermelonTop.png"
watermelon.bottom = "watermelonBottom.png"
watermelon.splash = "redSplash.png"
table.insert(avalFruit, watermelon)
local strawberry = {}
strawberry.whole = "strawberryWhole.png"
strawberry.top = "strawberryTop.png"
strawberry.bottom = "strawberryBottom.png"
strawberry.splash = "redSplash.png"
table.insert(avalFruit, strawberry)
-- Initialize splash images
table.insert(splashImgs, "splash1.png")
table.insert(splashImgs, "splash2.png")
table.insert(splashImgs, "splash3.png")
end
function getRandomFruit()
local fruitProp = avalFruit[math.random(1, #avalFruit)]
local fruit = display.newImage(fruitProp.whole)
fruit.whole = fruitProp.whole
fruit.top = fruitProp.top
fruit.bottom = fruitProp.bottom
fruit.splash = fruitProp.splash
return fruit
end
function getBomb()
local bomb = display.newImage( "bomb.png")
return bomb
end
function shootObject(type)
local object = type == "fruit" and getRandomFruit() or getBomb()
fruitGroup:insert(object)
object.x = display.contentWidth / 2
object.y = display.contentHeight + object.height * 2
fruitProp.radius = object.height / 2
physics.addBody(object, "dynamic", fruitProp)
if (type == "fruit") then
object:addEventListener("touch", function(event) chopFruit(object) end)
else
local bombTouchFunction
bombTouchFunction = function(event) explodeBomb(object, bombTouchFunction); end
object:addEventListener("touch", bombTouchFunction)
end
-- Apply linear velocity
local yVelocity = getRandomValue(minVelocityY, maxVelocityY) * -1 -- Need to multiply by -1 so the fruit shoots up
local xVelocity = getRandomValue(minVelocityX, maxVelocityX)
object:setLinearVelocity(xVelocity, yVelocity)
-- Apply angular velocity (the speed and direction the fruit rotates)
local minAngularVelocity = getRandomValue(minAngularVelocity, maxAngularVelocity)
local direction = (math.random() < .5) and -1 or 1
minAngularVelocity = minAngularVelocity * direction
object.angularVelocity = minAngularVelocity
end
function explodeBomb(bomb, listener)
bomb:removeEventListener("touch", listener)
-- The bomb should not move while exploding
bomb.bodyType = "kinematic"
bomb:setLinearVelocity(0, 0)
bomb.angularVelocity = 0
-- Shake the stage
local stage = display.getCurrentStage()
local moveRightFunction
local moveLeftFunction
local rightTrans
local leftTrans
local shakeTime = 50
local shakeRange = {min = 1, max = 25}
moveRightFunction = function(event) rightTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max), y = math.random(shakeRange.min, shakeRange.max), time = shakeTime, onComplete=moveLeftFunction}); end
moveLeftFunction = function(event) leftTrans = transition.to(stage, {x = math.random(shakeRange.min,shakeRange.max) * -1, y = math.random(shakeRange.min,shakeRange.max) * -1, time = shakeTime, onComplete=moveRightFunction}); end
moveRightFunction()
local linesGroup = display.newGroup()
-- Generate a bunch of lines to simulate an explosion
local drawLine = function(event)
local line = display.newLine(bomb.x, bomb.y, display.contentWidth * 2, display.contentHeight * 2)
line.rotation = math.random(1,360)
line.strokeWidth = math.random(15, 25)
linesGroup:insert(line)
end
local lineTimer = timer.performWithDelay(100, drawLine, 0)
-- Function that is called after the pre explosion
local explode = function(event)
audio.play(explosion)
blankOutScreen(bomb, linesGroup);
timer.cancel(lineTimer)
stage.x = 0
stage.y = 0
transition.cancel(leftTrans)
transition.cancel(rightTrans)
end
-- Play the preExplosion sound first followed by the end explosion
audio.play(preExplosion, {onComplete = explode})
timer.cancel(fruitTimer)
timer.cancel(bombTimer)
end
function blankOutScreen(bomb, linesGroup)
local gameOver = displayGameOver()
gameOver.alpha = 0 -- Will reveal the game over screen after the explosion
-- Create an explosion animation
local circle = display.newCircle( bomb.x, bomb.y, 5 )
local circleGrowthTime = 300
local dissolveDuration = 1000
local dissolve = function(event) transition.to(circle, {alpha = 0, time = dissolveDuration, delay = 0, onComplete=function(event) gameOver.alpha = 1 end}); gameOver.alpha = 1 end
circle.alpha = 0
transition.to(circle, {time=circleGrowthTime, alpha = 1, strokeWidth = display.contentWidth * 3, height = display.contentWidth * 3, onComplete = dissolve})
end
function displayGameOver()
-- Will return a group so that we can set the alpha of the entier menu
local group = display.newGroup()
-- Dim the background with a transperent square
-- local back = display.newRect( 0,0, display.contentWidth, display.contentHeight )
--back:setFillColor(0,0,0, 255 * .1)
--group:insert(back)
local gameOver = display.newImage( "gameover.png")
gameOver.x = display.contentWidth / 2
gameOver.y = display.contentHeight / 2
group:insert(gameOver)
local replayButton = ui.newButton{
default = "replayButton.png",
over = "replayButton.png",
onRelease = function(event) group:removeSelf(); main() ; end
}
group:insert(replayButton)
replayButton.x = display.contentWidth / 2
replayButton.y = gameOver.y + gameOver.height / 2 + replayButton.height / 2
return group
end
-- Return a random value between 'min' and 'max'
function getRandomValue(min, max)
return min + math.abs(((max - min) * math.random()))
end
function playRandomSlashSound()
audio.play(slashSounds["slash" .. math.random(1, 3)])
end
function playRandomChoppedSound()
audio.play(choppedSound["chopped" .. math.random(1, 2)])
end
function getRandomSplash()
return display.newImage(splashImgs[math.random(1, #splashImgs)])
end
function chopFruit(fruit)
if (sampleVar == true) then
displayScore()
playRandomChoppedSound()
createFruitPiece(fruit, "top")
createFruitPiece(fruit, "bottom")
createSplash(fruit)
createGush(fruit)
fruit:removeSelf()
end
end
-- Creates a gushing effect that makes it look like juice is flying out of the fruit
function createGush(fruit)
local i
for i = 0, numOfGushParticles do
local gush = display.newCircle( fruit.x, fruit.y, math.random(minGushRadius, maxGushRadius) )
gush:setFillColor(255, 0, 0, 255)
gushProp.radius = gush.width / 2
physics.addBody(gush, "dynamic", gushProp)
local xVelocity = math.random(minGushVelocityX, maxGushVelocityX)
local yVelocity = math.random(minGushVelocityY, maxGushVelocityY)
gush:setLinearVelocity(xVelocity, yVelocity)
transition.to(gush, {time = gushFadeTime, delay = gushFadeDelay, strokeWidth = 0, height = 0, alpha = 0, onComplete = function(event) gush:removeSelf() end})
end
end
function createSplash(fruit)
local splash = getRandomSplash()
splash.x = fruit.x
splash.y = fruit.y
splash.rotation = math.random(-90,90)
splash.alpha = splashInitAlpha
splashGroup:insert(splash)
transition.to(splash, {time = splashFadeTime, alpha = 0, y = splash.y + splashSlideDistance, delay = splashFadeDelayTime, onComplete = function(event) splash:removeSelf() end})
end
-- Chops the fruit in half
-- Uses some trig to calculate the position
-- of the top and bottom part of the chopped fruit (http://en.wikipedia.org/wiki/Rotation_matrix#Rotations_in_two_dimensions)
function createFruitPiece(fruit, section)
local fruitVelX, fruitVelY = fruit:getLinearVelocity()
-- Calculate the position of the chopped piece
local half = display.newImage(fruit[section])
half.x = fruit.x - fruit.x -- Need to have the fruit's position relative to the origin in order to use the rotation matrix
local yOffSet = section == "top" and -half.height / 2 or half.height / 2
half.y = fruit.y + yOffSet - fruit.y
local newPoint = {}
newPoint.x = half.x * math.cos(fruit.rotation * (math.pi / 180)) - half.y * math.sin(fruit.rotation * (math.pi / 180))
newPoint.y = half.x * math.sin(fruit.rotation * (math.pi / 180)) + half.y * math.cos(fruit.rotation * (math.pi / 180))
half.x = newPoint.x + fruit.x -- Put the fruit back in its original position after applying the rotation matrix
half.y = newPoint.y + fruit.y
fruitGroup:insert(half)
-- Set the rotation
half.rotation = fruit.rotation
fruitProp.radius = half.width / 2 -- We won't use a custom shape since the chopped up fruit doesn't interact with the player
physics.addBody(half, "dynamic", fruitProp)
-- Set the linear velocity
local velocity = math.sqrt(math.pow(fruitVelX, 2) + math.pow(fruitVelY, 2))
local xDirection = section == "top" and -1 or 1
local velocityX = math.cos((fruit.rotation + 90) * (math.pi / 180)) * velocity * xDirection
local velocityY = math.sin((fruit.rotation + 90) * (math.pi / 180)) * velocity
half:setLinearVelocity(velocityX, velocityY)
-- Calculate its angular velocity
local minAngularVelocity = getRandomValue(minAngularVelocityChopped, maxAngularVelocityChopped)
local direction = (math.random() < .5) and -1 or 1
half.angularVelocity = minAngularVelocity * direction
end
-- Creates a platform at the bottom of the game "catch" the fruit and remove it
function setUpCatchPlatform()
local platform = display.newRect( 0, 0, display.contentWidth * 4, 50)
platform.x = (display.contentWidth / 2)
platform.y = display.contentHeight + display.contentHeight
physics.addBody(platform, "static", catchPlatformProp)
platform.collision = onCatchPlatformCollision
platform:addEventListener( "collision", platform )
end
function onCatchPlatformCollision(self, event)
-- Remove the fruit that collided with the platform
event.other:removeSelf()
end
-- Draws the slash line that appears when the user swipes his/her finger across the screen
function drawSlashLine(event)
-- Play a slash sound
if(endPoints ~= nil and endPoints[1] ~= nil) then
local distance = math.sqrt(math.pow(event.x - endPoints[1].x, 2) + math.pow(event.y - endPoints[1].y, 2))
if(distance > minDistanceForSlashSound and slashSoundEnabled == true) then
playRandomSlashSound();
slashSoundEnabled = false
timer.performWithDelay(minTimeBetweenSlashes, function(event) slashSoundEnabled = true end)
end
end
-- Insert a new point into the front of the array
table.insert(endPoints, 1, {x = event.x, y = event.y, line= nil})
-- Remove any excessed points
if(#endPoints > maxPoints) then
table.remove(endPoints)
end
for i,v in ipairs(endPoints) do
local line = display.newLine(v.x, v.y, event.x, event.y)
line.strokeWidth = lineThickness
transition.to(line, {time = lineFadeTime, alpha = 0, strokeWidth = 0, onComplete = function(event) line:removeSelf() end})
end
if(event.phase == "ended") then
while(#endPoints > 0) do
table.remove(endPoints)
end
end
end
main()

My buttons wont appear in corona sdk

Can anyone help me. i am facing the below issue:
I am developing a game that is about questions and answers.
i used widget API to add buttons.
in menu screen (Menu.lua) i added 2 buttons for now. Play and options.
once i press play it go to the 1st level.
now the problem is as below:
1- once i add the buttons to the groupScene. they disappear.
2- once i remove them from groupScene they will appear. and will appear in the next seen.
so what should i do. should i remove them one by one. or is there another solution.
code as below
1- Main.Lua
`W = display.viewableContentWidth
H = display.viewableContentHeight
local widget = require( "widget")
local composer = require("composer" )
composer.purgeOnSceneChange = true
display.setStatusBar(display.HiddenStatusBar)
-- most commonly used screen coordinates
centerX = display.contentCenterX
centerY = display.contentCenterY
screenLeft = display.screenOriginX
screenWidth = display.contentWidth - screenLeft * 2
screenRight = screenLeft + screenWidth
screenTop = display.screenOriginY
screenHeight = display.contentHeight - screenTop * 2
screenBottom = screenTop + screenHeight
display.contentWidth = screenWidth
display.contentHeight = screenHeight
local bg = display.newRect( 0, 0, 2000,3000 )
bg:setFillColor( .26, .26, .26 )
composer.gotoScene( "Menu",{effect = "slideDown"} )
`
2- Menu.lua
local sceneName = ...
local composer = require( "composer" )
local scene = composer.newScene("Menu")
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called
-- -----------------------------------------------------------------------------------------------------------------
-- Local forward references should go here
-- -------------------------------------------------------------------------------
local function tapped(event)
local id = event.target.id
if id == "Start" then
composer.gotoScene( "Level1", {effect = "slideDown"} )
print("Level 1")
else
composer.gotoScene( "About_Us", {effect = "slideDown"} )
print("about us")
end
end
-- "scene:create()"
function scene:create( event )
local widget = require( "widget")
local sceneGroup = self.view
-- Initialize the scene here
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
--local title = display.newText( "abed" , centerX, centerY ,"Helvetica", 20 )
------------------------------------------start
startButton = widget.newButton {
id = "Start",
onRelease = tapped,
defaultFile = "button.png",
overFile = "buttonclicked.png",
label = "إبدأ اللعبة",
labelColor = { default={ 1, 1, 1 } },
}
startButton.x=centerX
startButton.y = centerY+-50
--sceneGroup:insert( startButton )
------------------------------------------options
optionbutton = widget.newButton {
id = "options",
onRelease = tapped,
defaultFile = "button.png",
overFile = "buttonclicked.png",
label = "خيارات",
labelColor = { default={ 1, 1, 1 } }
}
optionbutton.x=centerX
optionbutton.y = centerY+50
--sceneGroup:insert( optionbutton )
--local start = display.newImageRect( [parent,], filename, [baseDir,], width, height )
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-------------------------------------------code
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen)
-- Insert code here to "pause" the scene
-- Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == "did" ) then
-- Called immediately after scene goes off screen
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's view
-- Insert code here to clean up the scene
-- Example: remove display objects, save state, etc.
end
-- -------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -------------------------------------------------------------------------------
return scene
3- Level1.lua
local sceneName = ...
local composer = require( "composer" )
local scene = composer.newScene("Level1")
-- -----------------------------------------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE unless "composer.removeScene()" is called
-- -----------------------------------------------------------------------------------------------------------------
local function tapped(event)
local id = event.target.id
if id == "option1" then
local answerCover = display.newRect( centerX, centerY, 400, 35)
answerCover:setFillColor( .26, .26, .26 )
local title = display.newText( "لقد ربحت" , centerX, centerY ,"Helvetica", 20 )
composer.gotoScene( "About_Us")
end
if id == "Option2" then
local answerCover = display.newRect( centerX, centerY, 400, 35)
answerCover:setFillColor( .26, .26, .26 )
local title = display.newText( "لقد خسرت" , centerX, centerY ,"Helvetica", 20 )
end
if id == "Option3" then
local answerCover = display.newRect( centerX, centerY, 400, 35)
answerCover:setFillColor( .26, .26, .26 )
local title = display.newText( "لقد خسرت" , centerX, centerY ,"Helvetica", 20 )
end
if id == "option4" then
local answerCover = display.newRect( centerX, centerY, 400, 35)
answerCover:setFillColor( .26, .26, .26 )
local title = display.newText( "لقد خسرت" , centerX, centerY ,"Helvetica", 20 )
end
end
-- Local forward references should go here
-- -------------------------------------------------------------------------------
-- "scene:create()"
function scene:create( event )
local widget = require( "widget")
local sceneGroup = self.view
local Q = display.newImageRect( "Questions/Q1.png", 300, 150 )
Q.x = centerX
Q.y = centerY-150
------------------------------------------option1
local option1 = widget.newButton {
id = "option1",
onRelease = tapped,
defaultFile = "button.png",
overFile = "buttonclicked.png",
label = "12",
labelColor = { default={ 1, 1, 1 } }
}
option1.x=centerX
option1.y = screenBottom-180
--sceneGroup:insert(option1)
------------------------------------------option2
local option2 = widget.newButton {
id = "Option2",
onRelease = tapped,
defaultFile = "button.png",
overFile = "buttonclicked.png",
label = "5",
labelColor = { default={ 1, 1, 1 } }
}
option2.x=centerX
option2.y = screenBottom - 130
------------------------------------------option3
local option3 = widget.newButton {
id = "Option3",
onRelease = tapped,
defaultFile = "button.png",
overFile = "buttonclicked.png",
label = "9",
labelColor = { default={ 1, 1, 1 } }
}
option3.x=centerX
option3.y = screenBottom-80
------------------------------------------option4
local option4 = widget.newButton {
id = "option4",
onRelease = tapped,
defaultFile = "button.png",
overFile = "buttonclicked.png",
label = "4",
labelColor = { default={ 1, 1, 1 } }
}
option4.x=centerX
option4.y = screenBottom -30
-- Initialize the scene here
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
-- local title = display.newText( "abed" , centerX, centerY ,"Helvetica", 20 )
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen)
elseif ( phase == "did" ) then
-- Called when the scene is now on screen
-- Insert code here to make the scene come alive
-- Example: start timers, begin animation, play audio, etc.
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen)
-- Insert code here to "pause" the scene
-- Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == "did" ) then
-- Called immediately after scene goes off screen
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
-- Called prior to the removal of scene's view
-- Insert code here to clean up the scene
-- Example: remove display objects, save state, etc.
end
-- -------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
-- -------------------------------------------------------------------------------
return scene

Attempt to Index GlobalCredits 'event' (a nil value)

I have just started to learn LUA in school, but i cannot find many helpful tutorials o the internet to aid in my learning. I have made a simple game (which doesn't work yet, i realize that) and a main menu. However, when i try to start the app, it gives me this error:
/Users/jordanmcbride/Desktop/Lua Projects/Tapinator/main.lua:47: attempt to index global 'showCredits' (a nil value)
stack traceback:
/Users/jordanmcbride/Desktop/Lua Projects/Tapinator/main.lua:47: in main chunk
[Finished in 9.4s]
I have looked the error, and I cannot seem to understand how to fix it. The other questions have said something about returning the function returning a nil value, and that I should add a return statement to the end, but that doesn't work either.
Here is the code # line 47.
function showCredits.touch(e)
playButton.isVisible = false
creditsButton.isVisible = false
creditsView = display.newImage('credits.png', 0, display.contentHeight)
lastY = name.y
transition.to(name, {time = 300, y = display.contentHeight * 0.5 - title.height - 25})
transition.to(creditsView, {time = 300, y = display.contentHeight * 0.5 + creditsView.height, onComplete = function() creditsView:addEventListener('tap', hideCredits) end})
end
Here is my full code, in case the problem lies elsewhere:
display.setStatusBar(display.HiddenStatusBar)
radius = 40
smallTime = 200
bigTime = 800
score = 0
scoreInc = 2000
--HomePage
local name
local playButton
local creditsButton
local homePage
--Credits
local creditsPage
--Sounds
local circleSpawn = audio.loadSound( "circle_spawn.wav" )
local circleTap = audio.loadSound( "circle_tap.wav" )
function Main()
name = display.newImage('title.png', display.contentWidth / 2, 53)
name:scale( .5, .5 )
playButton = display.newImage('playButton.png', display.contentWidth / 2, 245)
playButton:scale( .5, .5 )
creditsButton = display.newImage('creditsButton.png', display.contentWidth / 2, 305)
creditsButton:scale( .5, .5 )
homePage = display.newGroup(name, playButton, creditsButton)
startButtonListeners('add')
end
function showCredits.touch(e)
playButton.isVisible = false
creditsButton.isVisible = false
creditsView = display.newImage('credits.png', 0, display.contentHeight)
lastY = name.y
transition.to(name, {time = 300, y = display.contentHeight * 0.5 - title.height - 25})
transition.to(creditsView, {time = 300, y = display.contentHeight * 0.5 + creditsView.height, onComplete = function() creditsView:addEventListener('tap', hideCredits) end})
end
function hideCredits.touch(e)
transition.to(creditsView, {time = 300, y = display.contentHeight, onComplete = function() creditsButton.isVisible = true playButton.isVisible = true creditsView:removeEventListener('tap', hideCredits) display.remove(creditsView) creditsView = nil end})
transition.to(name, {time = 300, y = lastY});
end
function startButtonListeners(action)
if(action == 'add') then
playButton:addEventListener('touch', playGame)
creditsButton:addEventListener('touch', showCredits)
else
playButton:removeEventListener('touch', playGame)
creditsButton:removeEventListener('touch', showCredits)
end
end
Main()
printScore = display.newText("Score: " .. tostring(score), display.contentWidth-80, 40, native.systemFontBold, 20)
-- A function that creates random circles
function generateCircle ()
-- Creates a new circle between 0 (the left most bounds) and the width of the display (being the content width), and also
-- 0 (the upper most bounds) and the height of the display (being the content height). The radius of the circle is 'radius'
x = math.random(radius, display.contentWidth-radius)
y = math.random(80, display.contentHeight)
score = score + scoreInc
myCircle = display.newCircle( x, y, radius )
myCircle:setFillColor( math.random(), math.random(), math.random() )
delayTime = math.random(smallTime, bigTime)
score = score + scoreInc
printScore.text = "Score:"..tostring(scores)
local spawnChannel = audio.play( circleSpawn )
timer.performWithDelay( delayTime, generateCircle )
end
generateCircle()
function myCircle:touch( event )
local tapChannel = audio.play( circleTap )
myCircle:removeSelf()
end
myCircle:addEventListener( "touch", myCircle )
The answer by greatwolf will work. But just a tip from my experience. One way I like to create functions is to try to define the name of the function first near the top of the lua file. Then I will define the function later on in the file. Something like this:
--function preallocation
local onPlayTap
local onSoundOnTap
local onSoundOffTap
local onCreditsTap
local onHelpTap
---------------------------------------------------------------------------------
-- Custom Function Definitions
---------------------------------------------------------------------------------
--Called when Sound On Button is tapped, turn off sound
onSoundOnTap = function(event)
end
--Called when Sound Off Button is tapped, turn on sound
onSoundOffTap = function(event)
end
--Called when Credits button is tapped, shows credits
onCreditsTap = function(event)
end
--Called when Help button is tapped, shows help
onHelpTap = function(event)
end
--Callback to Play button. Moves scene to Level Picker Scene
onPlayTap = function(event)
end
What this does is allow each function to be called by any other function in the file. If you do it the way you are doing it by adding the function name before the function like so:
local showCredits = {}
function showCredits.touch(e)
end
local hideCredits = {}
function hideCredits.touch(e)
end
your showCredit function will not be able to call the hideCredits function below it because the hideCredits variable has not been defined yet when the showCredit function was defined. Although this may not effect your current game, in future apps or games, you may need to call functions inside of other functions. To make this work properly, predefine all your function variables first, then define all your function afterwards. Hope this helps.

Failed to back to Menu from Game Over . Score unable to display on game over screen

I'm very new to corona. I learned all from the web and this is what i produced. The game seems fine but when game over screen is displayed, the button i put to back to menu scene doesn't work and the score that player get failed to be displayed to..
Here is my code...someone kindly please help me out.. what code should i change or add to it??
Thank you. Any help is much appreciated.
local composer = require( "composer" )
local scene = composer.newScene()
local physics = require("physics")
local widget = require "widget"
physics.start()
rand = math.random( 20 )
local slap_sound = audio.loadSound("Sound/slap2.mp3")
local ow = audio.loadSound("Sound/ow.mp3")
local buttonSound = audio.loadSound("Sound/sound2.mp3")
local background
local back
local count={total1=0,total=0,touch=0,life=3}
local total
local time_remain = 5
local mossie
local bee
local shade
local gameOverScreen
local winScreen
local countdown
local life
local pauseBtn
local resumeBtn
local gametmr
---------------------------------------------------------------------------------
-- All code outside of the listener functions will only be executed ONCE
-- unless "composer.removeScene()" is called.
---------------------------------------------------------------------------------
local gameOver = function()
composer.removeScene("easy")
physics.pause()
--audio.play(gameOverSound)
background = display.newImageRect( "Images/bg.jpg", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
gameOverScreen = display.newImage("Images/gameover.png",400,300)
gameOverScreen.x = 160
gameOverScreen.y = 240
gameOverScreen.alpha = 0
transition.to(gameOverScreen,{time=500,alpha=1})
--total.isVisible = true
total.text="Score : "..count.touch
total.x = 160
total.y = 400
--total:setTextColor(000000)
botwall.isVisible = false
mossie.isVisible = false
bee.isVisible = false
life.isVisible = false
countdown.isVisible = false
pauseBtn.isVisible = false
resumeBtn.isVisible = false
local myButton = widget.newButton
{
left = 100,
top = 100,
id = "myButton",
label = "Menu",
onEvent = handleButtonEvent
}
myButton.isVisible = true
end
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
composer.gotoScene ("menu")
end
end
local function countDown(e)
time_remain = time_remain-1
countdown.text = time_remain
if time_remain == 0 then
gameOver()
end
end
local pauseGame = function(e)
if(e.phase=="ended") then
audio.play(buttonSound)
physics.pause()
timer.pause(gametmr)
pauseBtn.isVisible = false
resumeBtn.isVisible = true
return true
end
end
local resumeGame = function(e)
if(e.phase=="ended") then
audio.play(buttonSound)
physics.start()
timer.resume(gametmr)
pauseBtn.isVisible = true
resumeBtn.isVisible = false
return true
end
end
local collisionListener=function(self,event)
if(event.phase=="began")then
if(event.other.type=="mossie")then
audio.play(ow)
count.life=count.life-1
if(count.life==0) then
gameOver()
end
event.other:removeSelf()
event.other=nil
else
event.other:removeSelf()
event.other=nil
end
end
end
function onTouch(mossie)
audio.play(slap_sound)
count.touch=count.touch+1
total.text="Score : "..count.touch
mossie.target:removeSelf()
end
function killIt(e)
if(e.phase == "ended") then
gameOver()
end
end
local bottomWall = function()
botwall=display.newImage("Images/tangan.png")
botwall.x = 160
botwall.y = 500
botwall:setFillColor(22,125,185,255)
botwall.type="botwall"
botwall.collision=collisionListener
physics.addBody(botwall,"static",{ density=100.0, friction=0.0, bounce=0.0} )
botwall:addEventListener("collision",botwall)
end
local function newMossie(event)
total.text="Score : "..count.touch
life.text="Life : "..count.life
mossie = display.newImage("Images/biasa.png")
mossie.x = 60 + math.random( 160 )
mossie.y = -100
mossie.type="mossie"
mossie:setFillColor(255,0,0)
physics.addBody( mossie, { density=0.3, friction=0.2, bounce=0.5} )
mossie.name = "mossie"
mossie:addEventListener("touch",onTouch)
end
local function newBee(event)
bee = display.newImage("Images/lebah.png")
bee.x = 60 + math.random( 160 )
bee.y = -100
bee.type="other"
physics.addBody( bee, { density=1.4, friction=0.3, bounce=0.2} )
bee:addEventListener("touch",killIt)
end
-- local forward references should go here
---------------------------------------------------------------------------------
-- "scene:create()"
function scene:create( event )
local sceneGroup = self.view
background = display.newImageRect( "Images/bg.jpg", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
total=display.newText("Score : 0",display.contentWidth * 0.5, 20, "Arial", 26)
total:setTextColor(000000)
countdown=display.newText(time_remain ,display.contentWidth * 0.9, 20, "Arial", 26)
countdown:setTextColor(000000)
life = display.newText("Life : 3 " ,display.contentWidth * 0.5, 50, "Arial", 26)
life:setTextColor(000000)
pauseBtn = display.newImage("Images/pause.png")
pauseBtn.x = display.contentWidth * 0.1
pauseBtn.y = display.contentHeight - 450
resumeBtn = display.newImage("Images/playb.png")
resumeBtn.x = display.contentWidth * 0.1
resumeBtn.y = display.contentHeight - 450
botwall=display.newImage("Images/tangan.png")
botwall.x = 160
botwall.y = 500
botwall:setFillColor(22,125,185,255)
botwall.type="botwall"
botwall.collision=collisionListener
physics.addBody(botwall,"static",{ density=100.0, friction=0.0, bounce=0.0} )
sceneGroup:insert(background)
sceneGroup:insert(total)
sceneGroup:insert(countdown)
sceneGroup:insert(life)
sceneGroup:insert(pauseBtn)
sceneGroup:insert(resumeBtn)
sceneGroup:insert(botwall)
resumeBtn.isVisible = false
pauseBtn:addEventListener("touch", pauseGame)
resumeBtn:addEventListener("touch", resumeGame)
botwall:addEventListener("collision",botwall)
dropMossie = timer.performWithDelay( 2000 , newMossie, -1 )
dropBee = timer.performWithDelay( 1800 , newBee, -1)
gametmr = timer.performWithDelay(1000, countDown, -1)
-- Initialize the scene here.
-- Example: add display objects to "sceneGroup", add touch listeners, etc.
end
-- "scene:show()"
function scene:show( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is still off screen (but is about to come on screen).
elseif ( phase == "did" ) then
-- Called when the scene is now on screen.
-- Insert code here to make the scene come alive.
-- Example: start timers, begin animation, play audio, etc.
end
end
-- "scene:hide()"
function scene:hide( event )
local sceneGroup = self.view
local phase = event.phase
if ( phase == "will" ) then
-- Called when the scene is on screen (but is about to go off screen).
-- Insert code here to "pause" the scene.
-- Example: stop timers, stop animation, stop audio, etc.
elseif ( phase == "did" ) then
-- Called immediately after scene goes off screen.
end
end
-- "scene:destroy()"
function scene:destroy( event )
local sceneGroup = self.view
--physics.stop()
--timer.cancel(gametmr)
--pauseBtn:removeEventListener("touch", pauseGame)
--resumeBtn:removeEventListener("touch", resumeGame)
--botwall:removeEventListener("collision",botwall)
--bee:removeEventListener("touch",killIt)
--mossie:removeEventListener("touch",onTouch)
-- Called prior to the removal of scene's view ("sceneGroup").
-- Insert code here to clean up the scene.
-- Example: remove display objects, save state, etc.
end
---------------------------------------------------------------------------------
-- Listener setup
scene:addEventListener( "create", scene )
scene:addEventListener( "show", scene )
scene:addEventListener( "hide", scene )
scene:addEventListener( "destroy", scene )
---------------------------------------------------------------------------------
return scene
I suggest to make another composer scene for gameOverScreen (just like you did with these code block you post). Then do a composer.gotoScene(gameOver) read more here. And for the score I suggest that you make something like this.
The funtion handleButtonEvent is declared after you are creating a button widget. You can get the desired result by moving the function about the widget code.
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
composer.gotoScene ("menu")
end
end
local myButton = widget.newButton
{
left = 100,
top = 100,
id = "myButton",
label = "Menu",
onEvent = handleButtonEvent
}
myButton.isVisible = true
end

How do i add a button to back to Main Menu (another .lua file)?

This game is something like killing mosquito. This is the level 1 file. When player tap the bee, game over will be displayed. When time's up, game over will be displayed. Total mosquitoes killed will be displayed at the end. I'm very very new to corona and to game development.
My question is:
Where to put in function to go back to main menu via "touch"? What is the code for it?
i'm using composer. So i tried composer.gotoScene("menu") but that doesn't seems to work. Error.
Thanks in advance for any help given. Here is part of the code:
local composer = require( "composer" )
local scene = composer.newScene()
local physics = require("physics")
local widget = require "widget"
physics.start()
rand = math.random( 20 )
local slap_sound = audio.loadSound("Sound/slap2.mp3")
local ow = audio.loadSound("Sound/ow.mp3")
local buttonSound = audio.loadSound("Sound/sound2.mp3")
local back
--local mossie_sound = audio.loadSound("Sound/mossie.mp3")
local count={total1=0,total=0,touch=0,life=3}
local background = display.newImageRect( "Images/bg.jpg", display.contentWidth, display.contentHeight )
background.anchorX = 0
background.anchorY = 0
background.x, background.y = 0, 0
local total=display.newText("Score : 0",display.contentWidth * 0.5, 20, "Arial", 26)
total:setTextColor(000000)
local time_remain = 30
local mossie
local bee
local shade
local gameOverScreen
local winScreen
local gameIsActive = false
local countdown=display.newText(time_remain ,display.contentWidth * 0.9, 20, "Arial", 26)
countdown:setTextColor(000000)
local life = display.newText("Life : 3 " ,display.contentWidth * 0.5, 50, "Arial", 26)
life:setTextColor(000000)
local pauseBtn = display.newImage("Images/pause.png")
pauseBtn.x = display.contentWidth * 0.1
pauseBtn.y = display.contentHeight - 450
local resumeBtn = display.newImage("Images/playb.png")
resumeBtn.x = display.contentWidth * 0.1
resumeBtn.y = display.contentHeight - 450
local gameOver = function()
composer.removeScene("level1") //scene cannot be removed???
gameIsActive = false
physics.pause()
gameOverScreen = display.newImage("Images/gameover.png",400,300)
gameOverScreen.x = 160
gameOverScreen.y = 240
gameOverScreen.alpha = 0
transition.to(gameOverScreen,{time=500,alpha=1})
total.isVisible = true
total.text="Score : "..count.touch
total.x = 160
total.y = 400
botwall.isVisible = false
mossie.isVisible = false
bee.isVisible = false
life.isVisible = false
countdown.isVisible = false
pauseBtn.isVisible = false
resumeBtn.isVisible = false
end
local collisionListener=function(self,event)
if(event.phase=="began")then
if(event.other.type=="mossie")then
audio.play(ow)
count.life=count.life-1
if(count.life==0) then
gameOver()
end
event.other:removeSelf()
event.other=nil
else
event.other:removeSelf()
event.other=nil
end
end
end
local function countDown(e)
time_remain = time_remain-1
countdown.text = time_remain
end
local checkTimer = function()
if(time_remain == 0) then
gameOver()
end
end
function killIt(e)
if(e.phase == "ended") then
gameOver()
end
end
--spawn Bee
local function newBee(event)
bee = display.newImage("Images/lebah.png")
bee.x = 60 + math.random( 160 )
bee.y = -100
bee.type="other"
physics.addBody( bee, { density=1.4, friction=0.3, bounce=0.2} )
checkTimer()
bee:addEventListener("touch",killIt)
end
---whenMossieIsTouched
function onTouch(mossie)
audio.play(slap_sound)
count.touch=count.touch+1
total.text="Score : "..count.touch
mossie.target:removeSelf()
--print("total"..mossietouchcount)
end
---spawn Mossie
local function newMossie(event)
--audio.play(mossie_sound)
total.text="Score : "..count.touch
life.text="Life : "..count.life
mossie = display.newImage("Images/biasa.png")
mossie.x = 60 + math.random( 160 )
mossie.y = -100
mossie.type="mossie"
mossie:setFillColor(255,0,0)
physics.addBody( mossie, { density=0.3, friction=0.2, bounce=0.5} )
mossie.name = "mossie"
--checkTimer()
mossie:addEventListener("touch",onTouch)
end
local bottomWall = function()
--botwall=display.newRect(0,display.contentHeight,display.contentWidth*2,10)
botwall=display.newImage("Images/tangan.png")
botwall.x = 160
botwall.y = 500
botwall:setFillColor(22,125,185,255)
botwall.type="botwall"
botwall.collision=collisionListener
physics.addBody(botwall,"static",{ density=100.0, friction=0.0, bounce=0.0} )
botwall:addEventListener("collision",botwall)
end
local gameActivate = function()
gameIsActive = true
end
local gameStart = function()
local gametmr = timer.performWithDelay(1000, countDown, 0)
local dropMossie = timer.performWithDelay( 1000 , newMossie, -1 )
local dropBee = timer.performWithDelay( 1800 , newBee, -1)
local pauseGame = function(e)
if(e.phase=="ended") then
audio.play(buttonSound)
physics.pause()
timer.pause(gametmr)
pauseBtn.isVisible = false
resumeBtn.isVisible = true
return true
end
end
local resumeGame = function(e)
if(e.phase=="ended") then
audio.play(buttonSound)
physics.start()
timer.resume(gametmr)
pauseBtn.isVisible = true
resumeBtn.isVisible = false
return true
end
end
pauseBtn:addEventListener("touch", pauseGame)
resumeBtn:addEventListener("touch", resumeGame)
resumeBtn.isVisible = false
bottomWall()
gameActivate()
end
gameStart()
return scene
Make sure the scene is called "menu.lua" when you try to use the composer.gotoScene("menu")
First make sure you require the libraries at the top
local composer = require( "composer" )
local widget = require( "widget" )
Then add a listener that will handle the button events
local function handleButtonEvent( event )
if ( "ended" == event.phase ) then
composer.gotoScene ("menu")
end
end
And then create the button
local myButton = widget.newButton
{
left = 100,
top = 200,
id = "myButton",
label = "Default",
onEvent = handleButtonEvent
}
EDIT:
Looking at your code I can see you aren't actually using composer. Sure you might be including the libraries but you aren't setting up any of the functions required for it to work.
I suggest you read this article: Introducing the Composer API. This will guide you through the use of composer.
At the very least you should have the following functions for composer to work.
scene:create()
scene:show()
scene:hide()
scene:delete()
And within those utilize the the scene's view using local sceneGroup = self.view. Once objects been inserted into this properly you can have “manage” your scene and the display objects within.

Resources