Storyboard/Composer question

Thanks for the input @Rob!!! You are so much better at tutoring then me haha. I tend to like to sit there and do things quietly and just know what i’m doing in my head.

Thanks!

Hope Rob’s post helps you!!!

Good Luck!

Thanks a lot you guys I’ll check out the code and get back to you with the results

Just a quick question though as if I have this right

Does this just set the background? also, what goes in “put background in here”? just the PNG file?

function scene:create( event )

    local sceneGroup = self.view  

    --Put background in here

end

function scene:show( event )

    local sceneGroup = self.view

    local phase = event.phase

    if ( phase == “did” ) then

(code goes here)

    end

end

Is that the part that actually runs the scene? And all the buttons/objects/counters all go in there as they would normally?

What do these two lines do?

scene:addEventListener( “create”, scene )

scene:addEventListener( “show”, scene )

Thanks!

Hello! Once again… Next time can you post your code in the editor? Thanks!

Ok so in the background… You can add any images you need to display… Just nothing anything that you’ll need to access like btns etc…

And the “(code goes here)” you put all the stuff you said the timers objects counters…

And those last 2 lines are listener’s to initiate the scene…

Good Luck!

Thanks a lot for all the help guys, I’ll go try the things you’ve suggested soon I just have a few what i hope are simpler (maybe stupid) questions.

function scene:create( event ) local sceneGroup = self.view --Put background in here end 

All the above does is set the background, right? also what goes in “–put background here”? is it just the “XXXX.PNG”?

Also, what does self.view do?

function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did" ) the (insert code here) end end

Is the above code what actually runs/happens in the scene? all code such as buttons, images, text displayed in the scene goes there?

sceneGroup:insert(deckbuilderbtn)

Does this add the function to the ‘local sceneGroup’? is this so that it disappears when you leave the scene?

Also, i’ve been curious for a while what the following three lines of code do and it would be great if someone could tell me what they do  individually (i like to understand what each command does rather than learning blocks of code to copy/paste)

Thanks!

scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

Hey again, I’m at an appointment atm… If no one helps you I’ll be back soon!

What @SonicX278 meant by “–Put background in here” is you create any objects that you need to display there, such as:

local background = display.newImageRect(“background.png”, 570, 360)

background.x = display.contentCenterX

background.y = display.contentCenterY

local scoreLabel = display.newText(“Score:”, 50, 25, native.systemFontBold, 18)

local btn = widget.newButton({

})

(using code examples above).

Then when he writes:  (insert code here)

he’s saying to put other code you need (we don’t know what you need) in here. There is however only some code you should put there. Only put things that start things in motion:  Physics, Timers, Transitions, Audio Playing, Runtime listeners, etc.

Rob

Thanks a lot guys its working now, you’ve been very helpful

Thanks @Rob for explaining! Didn’t have the time to do it.

@lazarfn, Your welcome! Hope your game comes together! Good Luck!

New question sorry…

but i cant seem to solve the error im getting here

Local function addCardOne( event ) if ("ended" == event.phase) then deck.insert( {(cardIndex[one])} ) end end

it says the error is on line 110 and it expects an ‘=’ near ‘function’

just to clarify im trying to insert a row from one table ( {…=…, …=… etc}) into another table where cardIndex is the first table and i want row ‘one’, and deck is the second table.

‘one’ is a local variable im using to keep track of cards as a new set is dealt each time a button is pressed. Basically it is some number, not necessarily one.

edit: nevermind, turns out i’d capitalized Local which meant it wasnt a command anymore

Edit2:

I’ve run into another problem

local cardIndex = ( { cat = a, subcat = a, cardType = a, name = a, def = a, atk = a, effect = a, pic = "jack1.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack2.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack3.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack4.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack5.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack6.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack7.png" , exist = 1 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 } { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 } ) return cardIndex

for the moment all im using is the ‘pic’ part of the table to test part of my app, it gives an error saying an error at line 3 where it expects ) to close the ( from line one beside ‘{’

I cant see what could be an error… Have you tried commenting out or removing line 3? If so what happens?

But try this.

local cardIndex = ( { cat = a, subcat = a, cardType = a, name = a, def = a, atk = a, effect = a, pic = "jack1.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack2.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack3.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack4.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack5.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack6.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = "jack7.png" , exist = 1 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 }, { cat = a, subcat = a, cardType = a, name = , def = a, atk = a, effect = a, pic = a, exist = 0 } ) return cardIndex

Thanks.

Thanks, yeah it was the , missing after the rows. 

Sorry i’m asking so many questions i’ll try to figure out the next few myself

No problem! The forums are meant for helping out fellow programmers! If you have any other questions you can ask here without hesitation! Ill be glad to help and i’m sure others will also! But for future reference can you please make new forum topics regarding the question you have? So they others with the same question can find your topic and fix their problem!

Thanks and Good Luck!!!

Hi @lazarfn,

Welcome to Corona! Composer is the official scene management library (Storyboard is officially deprecated), and while it takes a little bit of “up-front learning”, once you get accustomed to it, you’ll likely not use another method/ :slight_smile:

In regards to tutorials and guides, have you seen all of the resources outlined here?

https://coronalabs.com/blog/2015/08/11/tutorial-treasury-composer/
 

Hope this helps,

Brent

Welcome to corona SDK!!!

Try this!?

Main.lua

local composer = require( "composer" ) composer.gotoScene( "Menu" )

Menu.lua

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local BG = display.newRect(display.contentCenterX, display.contentCenterY, 1080, 1920) BG:setFillColor(1, 0, 0) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did" ) then local counter = 0 local counterTimer local counterTxt = display.newText( "0", 0, 0, native.systemFontBold, 40 ) counterTxt.x = display.contentCenterX counterTxt.y = 20 counterTxt:setFillColor(0, 0, 1) sceneGroup:insert(counterTxt) local function updateCounter(event) counter = counter + 1 counterTxt.text = string.format("%d", counter ) end local counterTimer = timer.performWithDelay( 1000, updateCounter, -1 ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

Ok so try that and you sound be set! 

Good Luck!

I tried directly copy and pasting the above code and it returns an error

module “menu.lua” not found

Also, from there, how would i navigate between .lua files? sorry if its a stupid question I’m genuinely confused.

As for the tutorials, yes I have looked through those resources as well as others on this website and havent had any success yet.

The code is supposed to work.

Can you add me on Skype? I can help you there?

RuvimKuz2000

Thanks! 

Please look at the code again and retry it… I made a stupid mistake and fixed it.

Thanks!

Im sorry im being soo lazy today and not checking my code haha.

Here is the redone and working code…

local composer = require( "composer" ) composer.gotoScene( "Menu" )

Menu.lua

local composer = require( "composer" ) local scene = composer.newScene() function scene:create( event ) local sceneGroup = self.view local BG = display.newRect(display.contentCenterX, display.contentCenterY, 1080, 1920) BG:setFillColor(1, 0, 0) sceneGroup:insert( BG ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did" ) then local counter = 0 local counterTimer local counterText = display.newText( "0", display.contentCenterX, display.contentCenterX, native.systemFontBold, 70) counterText:setFillColor( 0, 0, 1 ) sceneGroup:insert(counterText) local function updateCounter(event) counter = counter + 1 counterText.text = string.format("%d", counter ) end local counterTimer = timer.performWithDelay( 1000, updateCounter, -1 ) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

Good Luck!

Ok haha ONE more post and i think i have what you need…

Main.lua

local composer = require( "composer" ) composer.gotoScene( "Menu" )

Menu.lua

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") function scene:create( event ) local sceneGroup = self.view local BG = display.newRect(display.contentCenterX, display.contentCenterY, 1080, 1920) BG:setFillColor(1, 0, 0) sceneGroup:insert( BG ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did" ) then local counter = 0 local counterTimer local counterText = display.newText( "0", display.contentCenterX, display.contentCenterX, native.systemFontBold, 70) counterText:setFillColor( 0, 0, 1 ) sceneGroup:insert(counterText) local function updateCounter(event) counter = counter + 1 counterText.text = string.format("%d", counter ) end local counterTimer = timer.performWithDelay( 1000, updateCounter, -1 ) local function GotoGame(event) if event.phase == "ended" then timer.cancel(counterTimer) display.remove(counterText) composer.gotoScene( "game", { time = 1000, effect = crossFade }) end end local btn = widget.newButton { top = display.contentCenterY, left = display.contentCenterX - 80, width = 84, height = 105, font = native.systemFontBold, id = "button1", label = "Press To Go To Game", onEvent = GotoGame } sceneGroup:insert(btn) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

Game.lua

local composer = require( "composer" ) local scene = composer.newScene() local widget = require("widget") function scene:create( event ) local sceneGroup = self.view local BG = display.newRect(display.contentCenterX, display.contentCenterY, 1080, 1920) BG:setFillColor(0, 0, 1) sceneGroup:insert( BG ) end function scene:show( event ) local sceneGroup = self.view local phase = event.phase if ( phase == "did" ) then local counter = 100 local counterTimer local counterText = display.newText( "100", display.contentCenterX, display.contentCenterX, native.systemFontBold, 70) counterText:setFillColor( 1, 0, 0 ) sceneGroup:insert(counterText) local function updateCounter(event) counter = counter - 1 counterText.text = string.format("%d", counter ) end local counterTimer = timer.performWithDelay( 1000, updateCounter, -1 ) local function GotoMenu(event) if event.phase == "ended" then timer.cancel(counterTimer) display.remove(counterText) composer.gotoScene( "Menu", { time = 1000, effect = crossFade }) end end local btn = widget.newButton { top = display.contentCenterY, left = display.contentCenterX - 80, width = 84, height = 105, font = native.systemFontBold, id = "button1", label = "Press To Go To Menu", onEvent = GotoMenu } sceneGroup:insert(btn) end end scene:addEventListener( "create", scene ) scene:addEventListener( "show", scene ) return scene

So this code lets you go from menu to game and vice versa… 

Good Luck!

Thanks its working now, just wonderingdo the counters serve any purpose?

I was mostly wondering how i could implement this into a button since 

local composer = require( “composer” )
composer.gotoScene( “Menu” )

seems to suffice with “composer.gotoscene( “menu” )” being used as an event, however when i try making that a function for a button it returns an error

i.e

display.setStatusBar( display.HiddenStatusBar )      

local composer = require(“composer”)

local widget =require (“widget”)

local function godeckbuilder( event )

if (“ended” == event.phase) then

composer.gotoScene( “deckbuilder” )

end

end

local deckbuilderbtn = widget.newButton

{

width = 100,

height = 50,

defaultFile = “icon.png”,

overFile = “icon.png”,

label = “deck builder”,

onEvent = godeckbuilder,

}

buttondeckbuilderbtn.x = 10

buttondeckbuilderbtn.y = 10

and lastly, could you point out which bit of code takes take of removing the previous scene’s buttons, background and things?

thanks a lot though you’ve been very helpful

for the record, im trying to make a simple card game