Hey! This is my first open source release, so please do correct me if I screw anything up in this post.
LinkModule is a module used to link objects together by destruction. Normally you could just use models for this (model is destroyed, children are destroyed as well) however some complications can arise. What if you want two or more objects to have a mutually assured destruction? What if your child objects which you want to be destroyed span across different ancestries? What if you want more than one object to trigger the destruction of a group? These are the problems that this module solves.
Here are some function examples:
Functions
function 1:
linkmodule.deeplink({tableofitems})
If any of these items are destroyed, regardless of ancestry, all other items in the group will be destroyed as well.
function 2:
linkmodule.linkinstance(instance1, instance2)
If the first instance is destroyed, the second will be destroyed also. However, if the second instance is destroyed, it will have no effect on the first.
function 3:
linkmodule.linkgroup(instance1, {tableofitems})
If the first instance is destroyed (instance1), the group of objects will also be destroyed. If an instance inside of the group is destroyed, there are no effects (one way destruction).
function 4:
linkmodule.unlinkinstance(instance)
Un-links an instance from whatever group it was in. Also returns a bool of whether the operation succeeded or not.
function 5:
linkmodule.unlinkgroup(group)
Un-links a table of instances from whatever group they were in. Also returns a bool of whether the operation succeeded or not.
function 6:
linkmodule.getlinkedgroups()
Returns an array of all linked groups (groups are tables).
An important thing to note is that instances within the group can be under different hierarchies/ancestries without error. Even if an instance is parented to nil, it still is linked to the group. Also, changing the ancestry of instances does not sever any group connections unless specified with unlinkinstance()
or unlinkgroup()
.
The only things that you can link are instances which can be destroyed. Trying to link anything otherwise such as lua objects or workspace.Terrain will cause an error.
Thats it! thanks for reading, I hope this is useful to someone haha. If you encounter any issues such as bugs or memory leaks, please post them down below!
link to the module
please note that the model is packaged so the module is subject to updates and change