Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 02:54 AM |
Moving 50 parts on Heartbeat and detecting .Touched of those parts from 1 main script Or moving them all and detecting the .Touched of scripts within those parts?
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 02:55 AM |
of the parts from scripts within* x\
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Jan 2017 02:58 AM |
| The former is better because you only need to connect Heatbeat once, apart from that they're almost similar. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 03:30 AM |
These parts are spawned indefinitely, at most there will be ~40-50 in-game. When the parts touch something, they "die" and are removed by saying :Destroy() I disable the script before I :Destroy() the part. This doesn't leave any lingering connections within that disabled, correct? It is being destroyed by virtue of its parent part being destroyed, I'm assuming, and the :connection freed thusly.
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 13 Jan 2017 03:32 AM |
destroy disconnects all connections from the object it's called on
http://wiki.roblox.com/index.php?title=API:Class/Instance/Destroy |
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Jan 2017 03:36 AM |
| Yes but it's better to have a single event connected for all #### ##### than multiple events being constantly connected and disconnected. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 03:54 AM |
If I were connecting and disconnecting these events ~10 times per second, would I see a performance difference than just connecting heartbeat from a one main controller and .Touched on each part that is generated?
|
|
|
| Report Abuse |
|
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 13 Jan 2017 03:56 AM |
| I don't know if you'd _notice_ a difference but why not just handle it all from 1 script? |
|
|
| Report Abuse |
|
|
Lucas_Lua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7521 |
|
|
| 13 Jan 2017 03:57 AM |
| Either way, you're going to be creating a Touched event connection for each part, right? If that's the case, go with one main script rather than many little ones. You'll save a little memory that way, and probably a lot of headache in debugging. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 03:59 AM |
Controlling these goobers from 1 script would require a rework of several lengthy functions, so if it won't cause a noticeable dip in performance then I might just overlook it for now.
|
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 04:01 AM |
^ I'd still have to connect .Touched with each part as it's spawned from the main script, is that not relatively similar as from .Touched in a script parented to that part?
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 13 Jan 2017 04:05 AM |
I believe relatively similar yes, but I think there's a small difference in creating a thread and creating a new script.
I would say creating a thread is more efficient than creating a new script simply because it uses less data.
But I do not think it's that noticeable in the performance.
Note: this is my op opinion not actually sure if this is true |
|
|
| Report Abuse |
|
|
Lucas_Lua
|
  |
| Joined: 18 Jun 2008 |
| Total Posts: 7521 |
|
|
| 13 Jan 2017 04:06 AM |
| Connecting with multiple scripts rather than in the main one means Roblox has to allocate memory for the script object itself, and then the extra thread that the code will need (which will die after making the connection and ending its execution). Of course, this extra memory footprint is very tiny. For 50 parts it shouldn't hurt, but several hundred or more and you'll start to see an increase in memory. |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 04:06 AM |
Okay thanks guys I'll leave it for now.
|
|
|
| Report Abuse |
|
|
pketny
|
  |
| Joined: 27 Dec 2010 |
| Total Posts: 1162 |
|
|
| 13 Jan 2017 04:06 AM |
| What I meant but better explained ^ |
|
|
| Report Abuse |
|
|
Soybeen
|
  |
| Joined: 17 Feb 2010 |
| Total Posts: 21462 |
|
|
| 13 Jan 2017 04:06 AM |
Thanks for information on that threshold @lucas
|
|
|
| Report Abuse |
|
|