[Resolved] Problem with the storyboard !!

Hello all

I was working with the storyboard , and I faced a problem which is … the credits.lua file doesn’t work.

this is my codes :

main.lua

[code]display.setStatusBar( display.HiddenStatusBar )

local storyboard = require “storyboard”

storyboard.gotoScene( “menu” , “fade” , 400)[/code]
menu.lua

[code]local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

_H = display.contentHeight;
_W = display.contentWidth;
local function playBtnTouch(self , event)
if(event.phase == “ended”)then
storyboard.gotoScene(“game” , “slideLeft” , 500 )
return true
end
end
local function creditsBtnTouch (self , event)
if(event.phase == “ended”)then
storyboard.getScene(“credits” , “slideRight” , 500)
return true
end
end

function scene:createScene(event)
local screenGroup = self.view

local mbg = display.newImageRect(“images/menuBG.png” , _W , _H);
mbg:setReferencePoint(display.CenterReferencePoint);
mbg.x = _W/2; mbg.y = _H/2;

local playBtn = display.newImageRect(“images/play-btn.png” , 120 , 70);
playBtn:setReferencePoint(display.CenterReferencePoint);
playBtn.x = _W/2; playBtn.y = _H/2 + playBtn.height;
playBtn.touch = playBtnTouch

local creditsBtn = display.newImageRect(“images/credits-btn.png” , 120 , 70);
creditsBtn:setReferencePoint(display.CenterReferencePoint);
creditsBtn.x = _W/2; creditsBtn.y = _H/2 + playBtn.height + creditsBtn.height;
creditsBtn.touch = creditsBtnTouch

local title = display.newText(“Main menu!”,0,0, native.systemFont , 55);
title:setReferencePoint(display.CenterReferencePoint);
title.x = _W/2; title.y = title.height;

screenGroup:insert(mbg);
screenGroup:insert(title);
screenGroup:insert(playBtn);
screenGroup:insert(creditsBtn);

playBtn:addEventListener( “touch”, playBtn )
creditsBtn:addEventListener(“touch” , creditsBtn)

end

function scene:enterScene(event)

storyboard.purgeScene(“game”)
storyboard.purgeScene(“credits”)
end

scene:addEventListener( “createScene”, scene )
scene:addEventListener( “enterScene” , scene)

return scene[/code]

game.lua

[code]local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

_H = display.contentHeight;
_W = display.contentWidth;

local function backToMenu(self , event)
if (event.phase == “ended”)then
storyboard.gotoScene(“menu” , “slideRight” , 500)
return true
end
end

function scene:createScene(event)
local screenGroup = self.view

local gbg = display.newImageRect(“images/gameBG.png” , _W , _H);
gbg:setReferencePoint(display.CenterReferencePoint);
gbg.x = _W/2; gbg.y = _H/2;

local backBtn = display.newImageRect(“images/back.png” , 120 , 70);
backBtn:setReferencePoint(display.CenterReferencePoint);
backBtn.x = _W/2; backBtn.y = _H/2 + backBtn.height;
backBtn.touch = backToMenu

local title = display.newText(“The game!”,0,0, native.systemFont , 55);
title:setReferencePoint(display.CenterReferencePoint);
title.x = _W/2; title.y = title.height;

screenGroup:insert(gbg);
screenGroup:insert(backBtn);
screenGroup:insert(title);

backBtn:addEventListener(“touch” , backBtn);

end

function scene:enterScene(event)

storyboard.purgeScene(“menu”)

end

scene:addEventListener(“createScene” , scene);
scene:addEventListener( “enterScene” , scene);

return scene[/code]
credits.lua

[code]local storyboard = require (“storyboard”)
local scene = storyboard.newScene()

_H = display.contentHeight;
_W = display.contentWidth;
local function backToMenu(self , event)
if event.phase == “ended” then
storyboard.gotoScene(“menu” , “slideLeft” , 500)
return true
end
end

function scene:createScene(event)
local screenGroup = self.view

local cbg = display.newImageRect(“images/creditsBG.png” , _W , _H);
cbg:setReferencePoint(display.CenterReferencePoint);
cbg.x = _W/2; cbg.y = _H/2;

local backBtn = display.newImageRect(“images/back.png” , 120 ,70);
backBtn:setReferencePoint(display.CenterReferencePoint);
backBtn.x = _W/2; backBtn.y = _H/2 + backBtn.height;
backBtn.touch = backToMenu

local title = display.newText(“The credits!” , 0,0, native.systemFont , 55);
title:setReferencePoint(display.CenterReferencePoint);
title.x = _W/2; title.y = title.height;

screenGroup:insert(cbg)
screenGroup:insert(backBtn)
screenGroup:insert(title)

backBtn:addEventListener(“touch” , backBtn);
end

function scene:enterScene(event)

storyboard.purgeScene(“menu”)

end

scene:addEventListener(“createScene” , scene);
scene:addEventListener( “enterScene” , scene);

return scene[/code]
[import]uid: 133838 topic_id: 24475 reply_id: 324475[/import]

I haven’t used the storyboard but on your menu.lua you have on line 18.

[lua]storyboard.getScene[/lua]

instead of

[lua]storyboard.gotoScene[/lua]

Everywhere else you have “gotoScene”. I dunno if this might help. [import]uid: 123298 topic_id: 24475 reply_id: 99059[/import]

I change it to storyboard.gotoScene but it doesn’t work … and the terminal says:

"Runtime error ?:0:attempt to call method 'dispatchEvent'(a nil value) stack traceback: [c]: in function 'dispatchEvent' ?: in function 'gotoScene' \...\...\...\...\ menu.lua:18:in function " [import]uid: 133838 topic_id: 24475 reply_id: 99062[/import]

Do your functions need to be inside the enterScene() stage?

Also were you able to go to your game.lua file and then back with no problems? [import]uid: 123298 topic_id: 24475 reply_id: 99067[/import]

@miguelrico3d

1- I don’t know what’s enterScene() stage.

2- yes , when I hit the play button it’s running the game.lua file with no problems … also it works perfectly when I hit the back button. [import]uid: 133838 topic_id: 24475 reply_id: 99158[/import]

@wa7dawy.96
Just rename credits.lua to another name.
I think corona is confuse with a “credits” which refers to Super Rewards’ virtual currency library.

More info here: http://developer.anscamobile.com/forum/2012/02/25/director-error-module-credits-must-have-new-function [import]uid: 10491 topic_id: 24475 reply_id: 99180[/import]

@kirakorn

Thank you very very much :slight_smile:
I just rename it and every thing is work perfectly.

:slight_smile: [import]uid: 133838 topic_id: 24475 reply_id: 99181[/import]