Need help with composer

Hello, 

Please have a look at the code below: 


local function creditScreen (event) 

local obj = event.target

if event.phase ==“ended” 

then

obj:removeSelf()

obj=nil

button1:removeSelf()

button1=nil

button2:removeSelf()

button2=nil

composer.gotoScene(“credits”, “fade” ,500 )

end

return

end

button3 = widget.newButton

{

    label = “button3”,

    onEvent = creditScreen,

    emboss = true,

    shape=“roundedRect”,

    fontSize=25,

   cornerRadius = 20,

    fillColor = { default={0,0.95,0,0.7}, over={ 0.5,0.22,0,0.7 } },

    strokeColor = { default={ 0.5,0.22,0,1 }, over={ 0,1,0,1 } },

    strokeWidth =3,

    labelColor = { default={ 1, 1, 1,1 }, over={ 0, 1, 0, 1 } },

}

button3.x=v.centerX 

button3.y = v.centerY+320

button3:setLabel( “Credits” )

button3:scale(1.7,1.5)


Now when I click on “credit” button, an error flashes up. (Please see the error image attachment)

I have gone through the code in “events.lua” and seems fine to me (I mean the composer format and all is fine)

Also, I created a similar button which on-clicking switches to new screen; and it works perfect.

What does this error mean (as shown in attachment)??

Help please? 

Firstly, if you insert obj, button1, button2 into the scene view, you don’t need to remove and nil them manually.

Is this code from events.lua? If you are going to a scene called credits, the file must be called credits.lua.

No no … the above code is from “mainscreen.lua” . The mainscreen has a button named ‘credits’. When we press this button, credits.lua is opened. (For that I have called function creditScreen() )

Try

[lua]

composer.gotoScene(“credits”, {effect = “fade” ,time = 500})

[/lua]

If that doesn’t work, post credits.lua as it might be a syntax error on that file.

It didn’t work either … Here is the credit.lua code:


local composer = require(“composer”)

local widget = require( “widget” )

display.setStatusBar(display.HiddenStatusBar)


local grp= {} 

grp.main = display.newGroup() 

grp.screen =display.newGroup() 

local scene = composer.newScene()

local v = {}

v.centerX  = display.contentCenterX

v.centerY = display.contentCenterY

local gfx = {} 

composer.removeScene(“mainscreen”)


local function back(event) 

local obj2 = event.target

if event.phase ==“ended” 

then

obj2:removeSelf()

obj2=nil

composer.gotoScene( “mainscreen” )

end

end


local bg, textdisp, textdispName,textdispName2, img

function scene:create(event)

grp.main  = self.view

bg= display.newImageRect(grp.screen, “bgjpg.jpg”,1600, 1000)

bg.x=v.centerX

bg.y=v.centerY

bg.alpha=0.5

textdisp=display.newText( grp.screen, “THANKS TO :\n\n”, 0, 0, “native.systemFontBold”, 60 )

textdisp.x=v.centerX

textdisp.y=v.centery-150

textdispName = display.newText( grp.screen, “- (Name)\n\n\n”, 0, 0, “native.systemFontBold”, 40 )

textdispName.x=v.centerX

textdispName.y=v.centerY-250

textdispName2 = display.newText(grp.screen,  "Game created by : ", 0, 0, “native.systemFontBold”, 60 )

textdispName2.x=v.centerX

img=display.newImage(grp.screen,“logopng.png”)

img.x=v.centerX

img.y=v.centerY

gfx.img=img

button3 = widget.newButton

{

    label = “button”,

    onEvent = back,

    emboss = true,

    

    shape=“roundedRect”,

    fontSize=25,

    cornerRadius = 20,

    fillColor = { default={0,0.95,0,0.6}, over={ 0.5,0.22,0,0.7 } },

    strokeColor = { default={ 0.5,0.22,0,1 }, over={ 0,1,0,1 } },

    strokeWidth =3,

    labelColor = { default={ 1, 1, 1,1 }, over={ 0, 1, 0, 1 } },

}

button3.x=v.centerX

button3.y = v.centerY + 185

button3:setLabel( “<-- Back” )

button3:scale(2,2)

grp.main:insert(grp.screen)

end

function scene:show( event )

grp.main = self.view

local phase = event.phase

if phase==“did” 

then

trans=transition.blink (gfx.img, {time=1000})

end

end

function scene:hide(event)

grp.main = self.view

local phase=event.phase

if phase==“will”

then

transition.cancel(trans)

end

end

function scene:destroy( event )

grp.main = self.view

print( “((Destroyed credits view))” )

end


scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene


What I think is the error comes on entering the scene “credits.lua”. 

Please help.

The only error I can see at first glance is ‘textdisp.y=v.centery-150’ - lowercase ‘Y’ instead of uppercase.

That was my bad … I figured out this mistake while posting the code here and rectified it.

But, no luck. The same error flashes every time! :frowning:

What exactly does this error mean? I mean in what situation(s) does this error flash? 

It’s not really clear. You should get a more detailed error message in the console rather than this popup. Anything in there?

Okay … so … now what I did is created a new lua file, named it is “creds.lua” , copied the entire “credit.lua” file into it (as it is), linked the file in composer, and it worked :open_mouth:

I don’t know how, but it worked. Any idea how this happened? I mean … is ‘credits’ an already reserved word in lua library? Or something like that? Because I did not make any additional changes in “creds.lua” file … but it worked

There used to be an internal library named “credits”.  I always use the name “gamecredits.lua”

Rob

Oh okay… thanks!

Firstly, if you insert obj, button1, button2 into the scene view, you don’t need to remove and nil them manually.

Is this code from events.lua? If you are going to a scene called credits, the file must be called credits.lua.

No no … the above code is from “mainscreen.lua” . The mainscreen has a button named ‘credits’. When we press this button, credits.lua is opened. (For that I have called function creditScreen() )

Try

[lua]

composer.gotoScene(“credits”, {effect = “fade” ,time = 500})

[/lua]

If that doesn’t work, post credits.lua as it might be a syntax error on that file.

It didn’t work either … Here is the credit.lua code:


local composer = require(“composer”)

local widget = require( “widget” )

display.setStatusBar(display.HiddenStatusBar)


local grp= {} 

grp.main = display.newGroup() 

grp.screen =display.newGroup() 

local scene = composer.newScene()

local v = {}

v.centerX  = display.contentCenterX

v.centerY = display.contentCenterY

local gfx = {} 

composer.removeScene(“mainscreen”)


local function back(event) 

local obj2 = event.target

if event.phase ==“ended” 

then

obj2:removeSelf()

obj2=nil

composer.gotoScene( “mainscreen” )

end

end


local bg, textdisp, textdispName,textdispName2, img

function scene:create(event)

grp.main  = self.view

bg= display.newImageRect(grp.screen, “bgjpg.jpg”,1600, 1000)

bg.x=v.centerX

bg.y=v.centerY

bg.alpha=0.5

textdisp=display.newText( grp.screen, “THANKS TO :\n\n”, 0, 0, “native.systemFontBold”, 60 )

textdisp.x=v.centerX

textdisp.y=v.centery-150

textdispName = display.newText( grp.screen, “- (Name)\n\n\n”, 0, 0, “native.systemFontBold”, 40 )

textdispName.x=v.centerX

textdispName.y=v.centerY-250

textdispName2 = display.newText(grp.screen,  "Game created by : ", 0, 0, “native.systemFontBold”, 60 )

textdispName2.x=v.centerX

img=display.newImage(grp.screen,“logopng.png”)

img.x=v.centerX

img.y=v.centerY

gfx.img=img

button3 = widget.newButton

{

    label = “button”,

    onEvent = back,

    emboss = true,

    

    shape=“roundedRect”,

    fontSize=25,

    cornerRadius = 20,

    fillColor = { default={0,0.95,0,0.6}, over={ 0.5,0.22,0,0.7 } },

    strokeColor = { default={ 0.5,0.22,0,1 }, over={ 0,1,0,1 } },

    strokeWidth =3,

    labelColor = { default={ 1, 1, 1,1 }, over={ 0, 1, 0, 1 } },

}

button3.x=v.centerX

button3.y = v.centerY + 185

button3:setLabel( “<-- Back” )

button3:scale(2,2)

grp.main:insert(grp.screen)

end

function scene:show( event )

grp.main = self.view

local phase = event.phase

if phase==“did” 

then

trans=transition.blink (gfx.img, {time=1000})

end

end

function scene:hide(event)

grp.main = self.view

local phase=event.phase

if phase==“will”

then

transition.cancel(trans)

end

end

function scene:destroy( event )

grp.main = self.view

print( “((Destroyed credits view))” )

end


scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

scene:addEventListener( “hide”, scene )

scene:addEventListener( “destroy”, scene )


return scene


What I think is the error comes on entering the scene “credits.lua”. 

Please help.

The only error I can see at first glance is ‘textdisp.y=v.centery-150’ - lowercase ‘Y’ instead of uppercase.

That was my bad … I figured out this mistake while posting the code here and rectified it.

But, no luck. The same error flashes every time! :frowning:

What exactly does this error mean? I mean in what situation(s) does this error flash? 

It’s not really clear. You should get a more detailed error message in the console rather than this popup. Anything in there?

Okay … so … now what I did is created a new lua file, named it is “creds.lua” , copied the entire “credit.lua” file into it (as it is), linked the file in composer, and it worked :open_mouth:

I don’t know how, but it worked. Any idea how this happened? I mean … is ‘credits’ an already reserved word in lua library? Or something like that? Because I did not make any additional changes in “creds.lua” file … but it worked

There used to be an internal library named “credits”.  I always use the name “gamecredits.lua”

Rob