|
| 11 Dec 2011 09:41 PM |
=========== remove | Remove | ClearAllChildren | Destroy — What are they? Which to use? ===========
Ok, so I noticed there were lots of threads about this new update and, as HatHelper suggested, I decided to make a thread explaining everything.
- remove -
Instance:remove() was deprecated many months ago, at the same moment as findFirstChild, getChildren and many others. It was because they were inconsistent with ROBLOX's PascalCase (Workspace, StarterGui). Instead, you were (and still are) supposed to use FindFirstChild, GetChildren and Remove, as well as many others. Instance:remove() is currently exactly the same as Instance:Remove, except using Instance:Remove() is preferable to using Instance:remove() (because it is more consistent with the rest of the ROBLOX object system, even though, for reasons I'll mention soon, using either is already a bad idea.
- Remove -
Instance:Remove() was deprecated just now, in the precedent update. It isn't going to be removed, it's just that the admins won't update it or consider it anymore in future updates. It is kept only to make sure older scripts will still work, but you shouldn't use it in new scripts. I am serious about this, using deprecated features is just running straight into trouble.
- ClearAllChildren -
Instance:ClearAllChildren() is a new method that was just added, in this update. You can use it to clear an object from all its children. It removes every children of an object. It doesn't lock them or disconnect their events, unlike Destroy, though. ClearAllChildren doesn't remove the object it is called on, only its children.
- Destroy -
Instance:Destroy() does what its name says. It destroys an object. If you don't want an object anymore, if you won't need it again, you use this method. Basically, Destroy is the replacement of the Remove function. It has a better way of managing the memory and it has some other advantages over Remove.
Here is what Destroy does: • Puts the object in nil. • Locks the parent of the object, so you can't put it back in the game, which could cause errors. • Disconnects all the events of the objects, they're not needed anymore, so keeping them would just be a waste of memory. • Calls itself on all the childre of the object (meaning all the descendants of the object will be locked, put in nil, etc..).
Use Destroy whenever you don't need an object anymore. If you created a message, remove it using Destroy. If you need to regen a model, remove the old one using Destroy. If a player touched lava and you want to remove his head to kill him, use Destroy. Whenever you want to remove something, use Destroy. Whenever you don't need an object anymore, use Destroy.
-- Conclusion --
You don't NEED to update your old scripts (even though doing so is recommended), but don't use Remove anymore in the future. It is there only for backward compatibility, using it is just running into trouble. Instead, use Destroy, which has many advantages.
To replace every occurence of ":Remove()" in all of your scripts in a place by ":Destroy()", you can run this in command bar: function a(b) if b:IsA 'Script' then b.Source=b.Source:gsub(":remove",":Destroy") b.Source=b.Source:gsub(":Remove",":Destroy") end for _,child in pairs(b:GetChildren()) do a(child) end end a(game)
Sources:
• ROBLOX Object Browser • Experimentations (using the command bar) • Informations from stravant (xLEGOx) • My personal knowledge
--- JulienDethurens - Programmer |
|
|
| Report Abuse |
|
|
mage11561
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 13217 |
|
|
| 11 Dec 2011 09:44 PM |
I might understand this if I knew what "deprecated" meant.. Does that make me stupid ._. |
|
|
| Report Abuse |
|
|
|
| 11 Dec 2011 09:47 PM |
| Basically they won't update it and such.. |
|
|
| Report Abuse |
|
|
mage11561
|
  |
| Joined: 03 Sep 2008 |
| Total Posts: 13217 |
|
|
| 11 Dec 2011 09:49 PM |
Oh thanks socca, I looked up what it meant right after posting that, i thought it was a special scripting term or something that i didn't know, sorry :P |
|
|
| Report Abuse |
|
|
swmaniac
|
  |
| Joined: 28 Jun 2008 |
| Total Posts: 15773 |
|
|
| 11 Dec 2011 09:54 PM |
| Deprecated means essentially "outdated." It is unlikely that :remove() will ever be truly removed since this would break a ridiculous number of scripts, however use of :remove() should end and if it is practical you should change your old scripts to use :Destroy(). |
|
|
| Report Abuse |
|
|
blockoo
|
  |
| Joined: 08 Nov 2007 |
| Total Posts: 17202 |
|
|
| 11 Dec 2011 10:12 PM |
| So, ClearAllChildren() is just using Remove() on all the children? Why not Destroy() on all of the children? |
|
|
| Report Abuse |
|
|
MrGOBWEY
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 92 |
|
|
| 11 Dec 2011 10:27 PM |
"So, ClearAllChildren() is just using Remove() on all the children? Why not Destroy() on all of the children?"
That's what I thought it did...It doesn't make much sense to release a destroy method and use a depreciated method for a new function.
It looks like this in my mind (with object orientation not included, of course)
function ClearAllChildren(mdl) for _, v in pairs(mdl:GetChildren()) do v:Destroy() end end
---------- You should leave now... |
|
|
| Report Abuse |
|
|
|
| 11 Dec 2011 10:58 PM |
"Why not Destroy() on all of the children?"
No idea, I agree that using Destroy would be better.
But actually, no, ClearAllChildren doesn't use the Remove function, it just puts them all in nil manually. |
|
|
| Report Abuse |
|
|
|
| 11 Dec 2011 11:01 PM |
| Sorry for the ugly title and all of that, btw. ROBLOX's preview button is a lie. Don't trust it. |
|
|
| Report Abuse |
|
|