I need button help!

I dont understand what you mean by having a file called in scene.lua

Y U NO WORK???

You can find some excellent books on learning how to use Corona SDK here:

http://www.coronalabs.com/resources/books/ 

Hi @Max281.  It sounds like you don’t know what storyboard is or does.  Let me give you a “brief” intro.   Let’s start by looking at this video:

https://www.youtube.com/watch?v=y2x1m_j3yRA

This is for a game of mine.  With Storyboard,  your app is constructed from a “main.lua” file that handles initialization of things including the Storyboard system.  After that you hand off control to a storyboard scene.  A scene generally handles one task in your app like a splash screen, your menu, your game, your game over screen, help, game settings etc.

Each scene is its own .lua file located in the same folder as your main.lua file.  The filename is important, because that’s how you reference each scene.  So looking at the video, main.lua calls “splash.lua” which handles the spinning logo and the startup music.  When that completes, it automatically calls the storyboard.gotoScene() API call to load the menu scene.  The menu scene’s code exists in “menu.lua” which draws the logo, the funky rectangle and the 5 buttons that can be pressed. 

In the video, it shows Play being pressed which loads the scene “twentyq.lua” which does the spinning wheel.  Once the category is selected it jumps to “loading.lua”, then once the questions have been downloaded from the server, it goes on to “trivia.lua”.

All of this is accomplished by calling storyboard.gotoScene("scenename") where “scenename” is the name of the Lua file that you want to load and go to.  So my main.lua has this line in it:

–main.lua

local storyboard = require(“storyboard”)

– other code needed for my app

– at the bottom:

storyboard.gotoScene(“splash”)

This reads in the file “splash.lua” and starts executing that code.  In splash.lua, when the logo is done with its animation, there is another storyboard.gotoScene(“menu”) which load “menu.lua”.  So whatever goes in quotes in storyboard.gotoScene() needs to be a Lua  module file in  your projects with that name and a .lua extension.

Now each scene file has requirements to provide a framework that storyboard needs to work.  Below is the minimum template  you need for each and every scene file (keep in mind, “main.lua” is not a scene file, so you only need the two lines above in your main.lua.

local storyboard = require( "storyboard" ) local scene = storyboard.newScene() function scene:createScene( event )     local group = self.view end function scene:enterScene( event )     local group = self.view end function scene:exitScene( event )     local group = self.view end function scene:destoryScene( event )     local group = self.view      end --------------------------------------------------------------------------------- -- END OF YOUR IMPLEMENTATION --------------------------------------------------------------------------------- -- "createScene" event is dispatched if scene's view does not exist scene:addEventListener( "createScene", scene ) -- "enterScene" event is dispatched whenever scene transition has finished scene:addEventListener( "enterScene", scene ) -- "exitScene" event is dispatched before next scene's transition begins scene:addEventListener( "exitScene", scene ) -- "destroyScene" event is dispatched before view is unloaded, which can be -- automatically unloaded in low memory situations, or explicitly via a call to -- storyboard.purgeScene() or storyboard.removeScene(). scene:addEventListener( "destroyScene", scene ) --------------------------------------------------------------------------------- return scene

All of that code is required if you want Storyboard to work including that last “return scene” line.  You put any code needed to create the scene in the “createScene” function.  You put any code needed to start the scene running in “enterScene”, like starting transitions and such (since that function runs once the scene is on the screen).  This is also where you create any native objects like native.newTextFields, native.newWebView, etc.   Then in exitScene you stop any thing you started or created in enterScene.   We can save destroyScene for later, most of the time you don’t need to put anything in there.

So looking at your code, this function has two problems that need fixed and a third thing you probably should add:

local function changeScene( event )     if event.phase == "release" then           storyboard.gotoScene("in scene")     end end
  1. event.phase will never ever be the string “release” based on how your button is constructed (well it never will be period, but).  The possible options are “began”, “moved” and “ended”.  You probably want “ended” since that most emulates a mouse click on a computer.  Your function won’t do anything until you fix that.

  2. storyboard.gotoScene(“in scene”)  – do you have a module file named “in scene.lua” that is formatted like the template above in the same folder as your main.lua?  First you probably shouldn’t be using spaces in file names, like I said above.  If you do not have this scene module file, it’s not going to work.

  3. You probably should have a “return true” between the two “end” statements so the touch event doesn’t fall through to the underlying object.

Rob

hey I put it in and I want to know how my button can change to the next scene now. how is it done? 

this is my code

local storyboard = require( “storyboard” )

local scene = storyboard.newScene()

display.setStatusBar( display.HiddenStatusBar )

local bg = display.newImageRect( “helistart.png”, 480, 320 )

bg.x, bg.y = display.contentWidth / 2, display.contentHeight / 2

--------PLAY BUTTON--------

local widget = require( “widget” )

local function changeScene( event )

    if event.phase == “release” then

          storyboard.gotoScene(“game”)

    end

end

local playButton = widget.newButton

{

    left = 186,

    top = 160,

    width = 105,

    height = 105,

    defaultFile = “button.png”,

    overFile = “buttonclick.png”,

    onEvent = changeScene

}

--------PLAY BUTTON--------

function scene:createScene( event )

    local group = self.view

end

function scene:enterScene( event )

    local group = self.view

end

function scene:exitScene( event )

    local group = self.view

end

function scene:destoryScene( event )

    local group = self.view

    

end


– END OF YOUR IMPLEMENTATION


– “createScene” event is dispatched if scene’s view does not exist

scene:addEventListener( “createScene”, scene )

– “enterScene” event is dispatched whenever scene transition has finished

scene:addEventListener( “enterScene”, scene )

– “exitScene” event is dispatched before next scene’s transition begins

scene:addEventListener( “exitScene”, scene )

– “destroyScene” event is dispatched before view is unloaded, which can be

– automatically unloaded in low memory situations, or explicitly via a call to

– storyboard.purgeScene() or storyboard.removeScene().

scene:addEventListener( “destroyScene”, scene )


return scene