Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

display.remove(object) vs object:removeSelf()
Started by remiduchalard Dec 14 2016 02:51 AM

3 replies to this topic

Best Answer Rob Miracle , 14 December 2016 - 10:27 AM

display.remove() does a little more than above. First it tests to see if the object exists. Then it checks to see if it has a member named removeSelf() and that it's a function but for all practical purposes it saves you checking the object before calling removeSelf()

 

Rob 

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

remiduchalard

[GLOBAL: userInfoPane.html]
remiduchalard
  • Contributor

  • 191 posts
  • Corona SDK

Hi,

 

On doc I find that is faster to use display.remove(object) if we want to verify if the object is not nil but is it faster or the same time if we don't do the verification.

Does there is another way to remove object?

 

If we do that:

if object~=nil then
  object:removeSelf()
end

does it replace automaticly when we build by

display.remove(object)

?

Thanks

 

Rémi



[TOPIC: post.html]
#2

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 20,720 posts
  • Corona Staff

I believe that display.remove() is nothing more than:

if object~=nil then
  object:removeSelf()
end

I'm trying to verify it, but I believe that's the case.

 

Rob


  • remiduchalard likes this

[TOPIC: post.html]
#3

Rob Miracle

[GLOBAL: userInfoPane.html]
Rob Miracle
  • Moderator

  • 20,720 posts
  • Corona Staff

  Best Answer

display.remove() does a little more than above. First it tests to see if the object exists. Then it checks to see if it has a member named removeSelf() and that it's a function but for all practical purposes it saves you checking the object before calling removeSelf()

 

Rob 


  • remiduchalard likes this

[TOPIC: post.html]
#4

remiduchalard

[GLOBAL: userInfoPane.html]
remiduchalard
  • Contributor

  • 191 posts
  • Corona SDK

Thank you rob!




[topic_controls]
[/topic_controls]