changing scene in some seconds

I have down counting timer and want change scene when it is 0 but it does not work.
Code:

display.setStatusBar(display.HiddenStatusBar) \_W = display.contentWidth \_H = display.contentHeight number = 30  
   
local txt\_counter = display.newText( number, 0, 0, native.systemFont, 50 )  
txt\_counter.x = \_W/2  
txt\_counter.y = \_H/2  
txt\_counter:setTextColor( 255, 255, 255 )  
  
function fn\_counter()  
number = number - 1  
txt\_counter.text = number  
if number \< 1 then  
director.changeScene("scene1")  
end   
end  
  
tmr = timer.performWithDelay(1000, fn\_counter, number, 0)  

Error

Runtime error
/Users/Yurandus/Desktop/timer/main.lua:12: attempt to index global ‘director’ (a nil value)
stack traceback:
[C]: ?
/Users/Yurandus/Desktop/timer/main.lua:12: in function ‘_listener’
?: in function <?:531>
?: in function <?:226> [import]uid: 115740 topic_id: 34922 reply_id: 334922[/import]

Based on your error you need to require the director class.
like this:

local director = require ("director")

that should do the trick.
also be sure to have that file in your project folder.

and i would reccomend to take a look at ansca mobiles Storyboard since it does the same thing and i find it more veristile and easier than the director class.

http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/

and if you find storyboard interesting you could take a look at CoronaPaper #1 since it has an deepgoing tutorial for the storyboard API

www.coronapaper.com [import]uid: 134049 topic_id: 34922 reply_id: 138780[/import]

Silly mistake, thanks. Did it by using storyboard it works but I have an error.
Runtime error
?:0: attempt to concatenate global ‘sceneName’ (a nil value)
stack traceback:
[C]: ?
?: in function ‘gotoScene’
/Users/Yurandus/Desktop/timer/main.lua:15: in function ‘_listener’
?: in function <?:531>
?: in function <?:226>

[code]

display.setStatusBar(display.HiddenStatusBar) _W = display.contentWidth _H = display.contentHeight number = 30

local storyboard = require “storyboard”

local txt_counter = display.newText( number, 0, 0, native.systemFont, 50 )
txt_counter.x = _W/2
txt_counter.y = _H/2
txt_counter:setTextColor( 255, 255, 255 )

function fn_counter()
number = number - 1
txt_counter.text = number
if number < 1 then
storyboard.gotoScene( “qweasd” )
end
end

tmr = timer.performWithDelay(10, fn_counter, number, 0)
[/code] [import]uid: 115740 topic_id: 34922 reply_id: 138792[/import]

If you use storyboard,

  1. The scene name is the file name. So in your case there must be qweasd.lua in your base directory.
  2. The scene file (“qweasd” in this case) must have a scene setup in it!

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

function scene:createScene(event)
end

scene:addEventListener(“createScene”, scene)

return scene[/code]

It needs at least that much scene setup code, and possibly more depending on how you build it. (Here’s the easy template to use.) [import]uid: 41884 topic_id: 34922 reply_id: 138802[/import]

Of course I have qweasd.lua in directory :slight_smile:
Did as you said, it works. Thank you [import]uid: 115740 topic_id: 34922 reply_id: 138808[/import]

Based on your error you need to require the director class.
like this:

local director = require ("director")

that should do the trick.
also be sure to have that file in your project folder.

and i would reccomend to take a look at ansca mobiles Storyboard since it does the same thing and i find it more veristile and easier than the director class.

http://www.coronalabs.com/blog/2011/11/14/introducing-the-storyboard-api/

and if you find storyboard interesting you could take a look at CoronaPaper #1 since it has an deepgoing tutorial for the storyboard API

www.coronapaper.com [import]uid: 134049 topic_id: 34922 reply_id: 138780[/import]

Silly mistake, thanks. Did it by using storyboard it works but I have an error.
Runtime error
?:0: attempt to concatenate global ‘sceneName’ (a nil value)
stack traceback:
[C]: ?
?: in function ‘gotoScene’
/Users/Yurandus/Desktop/timer/main.lua:15: in function ‘_listener’
?: in function <?:531>
?: in function <?:226>

[code]

display.setStatusBar(display.HiddenStatusBar) _W = display.contentWidth _H = display.contentHeight number = 30

local storyboard = require “storyboard”

local txt_counter = display.newText( number, 0, 0, native.systemFont, 50 )
txt_counter.x = _W/2
txt_counter.y = _H/2
txt_counter:setTextColor( 255, 255, 255 )

function fn_counter()
number = number - 1
txt_counter.text = number
if number < 1 then
storyboard.gotoScene( “qweasd” )
end
end

tmr = timer.performWithDelay(10, fn_counter, number, 0)
[/code] [import]uid: 115740 topic_id: 34922 reply_id: 138792[/import]

If you use storyboard,

  1. The scene name is the file name. So in your case there must be qweasd.lua in your base directory.
  2. The scene file (“qweasd” in this case) must have a scene setup in it!

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

function scene:createScene(event)
end

scene:addEventListener(“createScene”, scene)

return scene[/code]

It needs at least that much scene setup code, and possibly more depending on how you build it. (Here’s the easy template to use.) [import]uid: 41884 topic_id: 34922 reply_id: 138802[/import]

Of course I have qweasd.lua in directory :slight_smile:
Did as you said, it works. Thank you [import]uid: 115740 topic_id: 34922 reply_id: 138808[/import]