Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

Should I check if composer.removeScene() is nil?
Started by dodi_games Aug 02 2018 10:37 AM

4 replies to this topic

Best Answer Rob Miracle , 05 August 2018 - 11:40 AM

It doesn't hurt to call composer.removeScene() on a scene that doesn't exist. You don't need to test if it was successful or not. 

 

Rob

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 324 posts
  • Corona SDK

Hi guys just want to know if it is safe to use composer.removeScene() as it is or I need to code some if statements. Tha case is that I need to remove 7 scenes in some specific scene an I make a local variable assignment for the scene name before removing it and the scene do not remove. But, if I call composer.removeScene() without the assignment the scenes remove. I'm using the composer.removeScene() in scene:show "did" phase.
 

-- show()
function scene:show( event )
 
    local sceneGroup = self.view
    local phase = event.phase
 
    if ( phase == "will" ) then
        -- Code here runs when the scene is still off screen (but is about to come on screen)
 
    elseif ( phase == "did" ) then
        composer.removeScene ("scenes/one")
        composer.removeScene ("scenes/two")
        composer.removeScene ("scenes/three")
        composer.removeScene ("scenes/four")
        composer.removeScene ("scenes/five")
        composer.removeScene ("scenes/six")
        composer.removeScene ("scenes/seven")
    end
end

------- or

 
    elseif ( phase == "did" ) then
        local removeScene1 = composer.getScene("scenes/one") 
        composer.removeScene (removeScene1) 
        -- same to scene seven
    end

I would like to know if I need to verify if the scene is "nil" before calling composer.removeScene()?

Thanks
DoDi



[TOPIC: post.html]
#2

Blex

[GLOBAL: userInfoPane.html]
Blex
  • Corona Geek

  • 1,197 posts
  • Corona SDK

Try testing it out, call it with a scene you know has been removed.



[TOPIC: post.html]
#3

dodi_games

[GLOBAL: userInfoPane.html]
dodi_games
  • Contributor

  • 324 posts
  • Corona SDK

@sdktester15

Nothing happens. Calling it alone does not give an error, but, if I put it inside a function, is more effective, even slow down the lua memory clock. I only do this topic to collect ideas and see which techniques are more efficient.

[TOPIC: post.html]
#4

Arteficio

[GLOBAL: userInfoPane.html]
Arteficio
  • Enthusiast

  • 79 posts
  • Corona SDK

Composer.removeScene requires a just string parameter, the scene name, not a display object.
composer.getScene returns a scene object, which is useless to a removeScene call.
  • dodi_games likes this

[TOPIC: post.html]
#5

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 24,969 posts
  • Corona Staff

  Best Answer

It doesn't hurt to call composer.removeScene() on a scene that doesn't exist. You don't need to test if it was successful or not. 

 

Rob


  • dodi_games likes this


[topic_controls]
[/topic_controls]