please help with code

this is my main.lua code 

local composer = require(“composer”)

composer.gotoScene(“scene1”)

this is my scene1.lua code 

local composer = require(“composer”)

local scene = composer.newScene()

local startup = display.newText(“CLICK ANYWHERE TO START”, 0, 0, native.systemFontBold,20)

local warning = display.newText("DONT FORGET THE NARWHALS A RAGING DIABETIC ", 0, 0, native.systemFontBold,20)

startup.x = display.viewableContentWidth /2

startup.y = display.viewableContentHeight  / 2 

warning.x = (display.viewableContentWidth /2) 

warning.y = (display.viewableContentHeight  / 2) + 50 

 local function start() 

local level = 55 

local score = 0 

local background = display.newImage(“black.png”, 0 , 0 )

background:scale(7,5)

local startup = display.newText(“CLICK ANYWHERE TO START”, 0, 0, native.systemFontBold,20)

local warning = display.newText(" Keep the Narwhals Blood Sugar between 50 and 60 ", 0, 0, native.systemFontBold,20)

startup.x = display.viewableContentWidth /2

startup.y = display.viewableContentHeight  / 2 

warning.x = (display.viewableContentWidth /2) 

warning.y = (display.viewableContentHeight  / 2) + 50 

end 

local function game(event)

local background = display.newImage(“water.jpg”,0, 0)

background:scale(2,2)

local good 

local physics = require(“physics”)

physics.start() 

–set a score label 

local level = 55

local score = 0

local scorelabel =  display.newText(level, 0, 0, native.systemFontBold,120)

scorelabel.x = display.viewableContentWidth /2

scorelabel.y = display.viewableContentHeight  / 2

scorelabel:setTextColor(0,0,0,10)

local timelabel =  display.newText(score, 0, 0, native.systemFontBold,70)

timelabel.x = 0

timelabel.y = 50

timelabel:setTextColor(0,0,0,10)

–create a player 

–creates and returns a new player 

local function createPlayer(x, y)

–player is a black square 

local p =  display.newImage(“narwhal.png”,x,y)

p:scale(2,2)

local playerCollisionFilter = {categoryBits = 2, maskBits = 5}

local playerBodyElement = {filter=playerCollisionFilter}

p.isbullet =true 

p.objectType = “player”

physics.addBody(p, “static”, playerBodyElement)

p.isSleepingAllowed = false 

return p

end 

local player = createPlayer(350,270)

local function stayOnScreen(object)

if object.x >= 500 then 

object.x =  500

end

if object.x <= 1  then

object.x = 2

end

 if object.y > 250   then

object.y = 250

end

 if object.y <= 270 then 

object.y = 270

end

end

local function onTouch(event)

if “began” == event.phase then 

player.isFocus = true

player.x0 = event.x - player.x

player.y0 = event.y - player.y

elseif player.isFocus then

if “moved” == event.phase then

player.x = event.x - player.x0

player.y = event.y - player.y0

stayOnScreen(player)

elseif “ended” == phase or “cancelled” == phase then

player.isFocus = false 

end 

end

return true

end 

background:addEventListener( “touch”, onTouch)

local function which()

local numba = math.random(1,3)

if numba == 1 then 

image = “orangegood.png”

end

if numba == 2 then 

image = “watermelon.png”

end

if numba == 3 then 

image = “apple.png”

end 

return image 

end 

–creates food 

local function spawn(objectType, x, y )

local object

local sizeXY = math.random(20,100)

local collisionFilter = {categoryBits = 4, maskBits = 2}

local body = {filter = collisionFilter, isSensor = true}

object = display.newImage(which(), x, y )

object.objectType = objectType

physics.addBody(object, body)

object.isFixedRoatation = true 

return object

end

local function shark (objectType, x, y )

local object

local sizeXY = math.random(20,100)

local collisionFilter = {categoryBits = 4, maskBits = 2}

local body = {filter = collisionFilter, isSensor = true}

object = display.newImage(“shark.png”, x, y )

object:scale(2,2)

object.objectType = objectType

physics.addBody(object, body)

object.isFixedRoatation = true 

return object

end

local function onTimer( event )

local green = spawn(“food”, math.random(1,500),-100)

end

timer.performWithDelay( 100, onTimer, 0 )

local function onTimer( event )

if level > 50 and level < 60 then

score = score + 1

timelabel.text = score

end 

end

timer.performWithDelay( 400, onTimer, 0 )

local function onTimer( event )

local blue = shark(“enemy”, math.random(1,500),-100 )

end

timer.performWithDelay( 100, onTimer, 0 )

–notification of collisionFilter

local function onCollision(event)

local type1 = event.object1.objectType

local type2 = event.object2.objectType

print("collision between " … type1 … " and " … type2)

if type1 == “food” or type2 == “food” then

level = level + .5

else

level = level - .5

end 

if level > 60  then 

for id, value in pairs(timer._runlist) do

     timer.cancel(value)

end

local widget = require(“widget”)

local function Restart(event)

    if “began” == event.phase then

       

     level = 55 

 score = 0

   storyboard.gotoScene(“scene2”)

    elseif “moved” == event.phase then

        --code here when  move

    elseif “ended” == event.phase or “cancelled” == event.phase then

        --code here when touch end

    end

end

– Create the widget

local button1 = widget.newButton{

    left = 100,

    top = 200,

    id = “button1”,

    label = “RESTART”,

    onEvent = Restart

}

end

if level < 50  then  

for id, value in pairs(timer._runlist) do

     timer.cancel(value)

end

local widget = require(“widget”)

local function Restart(event)

    if “began” == event.phase then

     

     level = 55 

 score = 0

  storyboard.gotoScene(“scene2”)

    elseif “moved” == event.phase then

        --code here when  move

    elseif “ended” == event.phase or “cancelled” == event.phase then

        --code here when touch end

    end

end

– Create the widget

local button1 = widget.newButton{

    left = 100,

    top = 200,

    id = “button1”,

    label = “RESTART”,

    onEvent = Restart

}

end

scorelabel.text = level 

end

Runtime:addEventListener(“collision”, onCollision)

end

Runtime:addEventListener(“touch”, game)

return scene

this is my scene2.lua code 

local composer = require(“composer”)

local scene = composer.newScene() 

local function goback(event)

if event.phaseif “began” == event.phase then

       

     

 composer.gotoScene(“scene1”)

    elseif “moved” == event.phase then

             

 composer.gotoScene(“scene1”)

    elseif “ended” == event.phase or “cancelled” == event.phase then

             

 composer.gotoScene(“scene1”)

end 

end 

local background = display.newImage(“black.png”, 0 , 0 )

background:scale(7,5)

local startup = display.newText(“CLICK ANYWHERE TO START”, 0, 0, native.systemFontBold,20)

local warning = display.newText("DONT FORGET THE NARWHALS A RAGING DIABETIC ", 0, 0, native.systemFontBold,20)

startup.x = display.viewableContentWidth /2

startup.y = display.viewableContentHeight  / 2 

warning.x = (display.viewableContentWidth /2) 

warning.y = (display.viewableContentHeight  / 2) + 50 

Runtime:addEventListener(“touch”, goback)

return scene  

if someone could please help me figure out why i can not get back from scene2 to scene1 this is for a school project in which i taught corona to myself so i am by no measure very knowledgable on this language and would appreciate some help 

thanks

you have storyboard.gotoScene(“scene2”)

instead of composer.gotoScene(“scene2”)

It would be really helpful to put your code inside the tags so it shows up as code.  You can use the <> in the bar above (in the row with Bold, Italic, etc.) or type in and (with the spaces) and put your code in between.

But it looks like to me that scene2 is missing it’s various events that are required:   scene:create(), scene:show(), scene:hide() and scene:destory().   You’re creating code in the main chunk, which  means it won’t be managed by a scene. 

I would look at some more of the composer tutorials including this past week’s tutorial at http://coronalabs.com/blog for more examples.

Rob

Rob

how do you implement such events I am brand new to composer and tutorials didnt help much

formatyourcode.jpg

you have storyboard.gotoScene(“scene2”)

instead of composer.gotoScene(“scene2”)

It would be really helpful to put your code inside the tags so it shows up as code.  You can use the <> in the bar above (in the row with Bold, Italic, etc.) or type in and (with the spaces) and put your code in between.

But it looks like to me that scene2 is missing it’s various events that are required:   scene:create(), scene:show(), scene:hide() and scene:destory().   You’re creating code in the main chunk, which  means it won’t be managed by a scene. 

I would look at some more of the composer tutorials including this past week’s tutorial at http://coronalabs.com/blog for more examples.

Rob

Rob

how do you implement such events I am brand new to composer and tutorials didnt help much

formatyourcode.jpg