Game Play Logic - 2

Sorry I was told to break different questions in to different topics.  Hope this is right.

anyway, I am creating a scene group for my composer called sceneGroup and I am passing it to called functions.  Now, when they touch a bubble a touchCircle function is called and an event is passed to it.  If that was the last circle then I want to call beginScreen again - the problem is I am getting an error message that says attempt to call method ‘insert’ (a nil value) because I no longer have sceneGroup in my grasps to call beginScreen. 

Something like this…

[lua]

function displayLevel(sceneGroup)

local levelText = nil
    local chooseModeText = nil
    level = level + 1
        levelText = display.newText(“Level - “…level…” Begin”,0,0,native.systemFontBold,25)
        levelText.anchorX=0
        levelText.x=25
        levelText:setFillColor(0)
        levelText.y=levelText.height/2 + 25
        sceneGroup:insert(levelText)

   displayImage(sceneGroup)

end

function touchCircle(event)

if (finished_count==10) then

   print(“YEAH!  You got them all!”)

   displayLevel(event) <-can’t do this.  That is an event - not a scene group. 

end

end

So, what can I do?  It appears I “lost” the sceneGroup

Thanks!

You do not have enough code here to give a completely accurate answer…  but I can assume somethings.

  1. the function ‘touchCircle’, I will assume is called from an eventListener you have attached to some circle object. That ‘event’ parameter sent to that function is automatically sent by corona when that function is called by the event listener.  It is a table.

  2. inside that function ‘touchCircle’, you call your function ‘displayLevel’ and pass on that ‘event’ table as a parameter.  So you are not passing the ‘sceneGroup’, that somewhere in your code you created.  sceneGroup parameter in that ‘displayLevel’ function is still that event table that was in ‘touchCircle’ function.

  3. I have to ‘assume’ here all this code, including your creating of a ‘sceneGroup’ is all in the same scene (that is in the same lua file).  

  4. Assuming that this code is all in one scene… maybe instead of passing the ‘sceneGroup’ to the functions within the file, make sceneGroup local to the file.  Declare it in the top part of the file (outside the scene:… functions).  In scene:create assign it to the scene view(scene view is ‘self.view’ is provided by composer).  Then it will be available to every function in the file.

for example:

-- mainScene.lua file &nbsp; local sg &nbsp; function scene:create( e ) sg = self.view &nbsp;-- assign the view here, and it will be useable in all functions and other scene events

If for some reason, you want a separate display group, in addition to the self.view that composer provides, I would do it the same way

by declaring the extra display group outside the ‘composer scene functions’ and define it in the scene:create … then it is available through this lua file(scene), and you do not have to pass it from function to function

for example:

-- mainScene.lua file &nbsp; local sg local myOtherGroup &nbsp; function scene:create( e ) sg = self.view myOtherGroup = display.newGroup() &nbsp;

hope this helps.

Thanks  cyberparkstudios!!!

That worked WONDERS!!!

Making the sceneGroup local at the beginning of the file did the trick!

Thank you so much!

You do not have enough code here to give a completely accurate answer…  but I can assume somethings.

  1. the function ‘touchCircle’, I will assume is called from an eventListener you have attached to some circle object. That ‘event’ parameter sent to that function is automatically sent by corona when that function is called by the event listener.  It is a table.

  2. inside that function ‘touchCircle’, you call your function ‘displayLevel’ and pass on that ‘event’ table as a parameter.  So you are not passing the ‘sceneGroup’, that somewhere in your code you created.  sceneGroup parameter in that ‘displayLevel’ function is still that event table that was in ‘touchCircle’ function.

  3. I have to ‘assume’ here all this code, including your creating of a ‘sceneGroup’ is all in the same scene (that is in the same lua file).  

  4. Assuming that this code is all in one scene… maybe instead of passing the ‘sceneGroup’ to the functions within the file, make sceneGroup local to the file.  Declare it in the top part of the file (outside the scene:… functions).  In scene:create assign it to the scene view(scene view is ‘self.view’ is provided by composer).  Then it will be available to every function in the file.

for example:

-- mainScene.lua file &nbsp; local sg &nbsp; function scene:create( e ) sg = self.view &nbsp;-- assign the view here, and it will be useable in all functions and other scene events

If for some reason, you want a separate display group, in addition to the self.view that composer provides, I would do it the same way

by declaring the extra display group outside the ‘composer scene functions’ and define it in the scene:create … then it is available through this lua file(scene), and you do not have to pass it from function to function

for example:

-- mainScene.lua file &nbsp; local sg local myOtherGroup &nbsp; function scene:create( e ) sg = self.view myOtherGroup = display.newGroup() &nbsp;

hope this helps.

Thanks  cyberparkstudios!!!

That worked WONDERS!!!

Making the sceneGroup local at the beginning of the file did the trick!

Thank you so much!