Skip to main content

AppliedMechanic

This was deprecated in v1.0.0
Part of the deprecated Mechanic package; use [Binder](/api/Binder) instead.

The object a Mechanic creates for each instance it is applied to. You get one from Mechanic:Apply, Mechanic:GetApplied or as the second argument of Mechanic:OnAdded. Do not construct it yourself; use Mechanic:Apply instead.

It owns a Trove that is cleaned (and the instance removed from the Mechanic) when the instance is destroyed, leaves the allowed Ancestors, or is revoked. Its Data field starts as a shallow copy (table.clone) of the Mechanic's Shared table unless data was passed to Apply, and newConstructor / bindToClass replace it with the constructed object.

local applied = Spinner:GetApplied(workspace.Windmill)
if applied then
	applied:GetData().Speed = 10
	applied.Trove:Add(function() print("cleaned") end)
end

This package is no longer maintained; see the deprecation notice on Mechanic.

Properties​

Instance​

This item is read only and cannot be modified. Read Only
AppliedMechanic.Instance: Instance

The instance this mechanic is applied to.

Mechanic​

This item is read only and cannot be modified. Read Only
AppliedMechanic.Mechanic: Mechanic<T>

The Mechanic that created this object.

Shared​

This item is read only and cannot be modified. Read Only
AppliedMechanic.Shared: T

The Mechanic's shared table (the same table for every instance).

Data​

AppliedMechanic.Data: T

Per-instance data. A shallow copy of Shared, the data passed to Apply, or the object built by newConstructor / bindToClass.

Trove​

AppliedMechanic.Trove: Trove

A Trove extended from the Mechanic's Trove. It is cleaned when the instance is destroyed, untagged, leaves the allowed ancestors, or Destroy is called; put per-instance connections in it.

Functions​

new​

AppliedMechanic.new(
mechanic: Mechanic<T>,--

The mechanic being applied.

instance: Instance,--

The instance to apply it to.

data: T?--

Initial Data; defaults to a shallow copy of mechanic.Shared.

) → AppliedMechanic<T>--

The new applied mechanic.

Constructs a new AppliedMechanic for instance, registers it in mechanic.Applications, attaches its Trove to the instance and fires mechanic.InstanceAdded. Called by Mechanic:Apply; you should not need to call it directly because it skips the duplicate check and does not add the tag.

GetData​

AppliedMechanic:GetData() → T--

The per-instance data.

Returns the per-instance data associated with this applied mechanic (the same table as the Data field).

GetShared​

AppliedMechanic:GetShared() → T--

The Mechanic's shared table.

Returns the shared table inherited from the Mechanic config. It is shared by every instance of the mechanic, so changes here affect all of them.

Destroy​

AppliedMechanic:Destroy() → ()

Cleans the Trove, removes the instance from the Mechanic's Applications and fires InstanceRemoved. The tag stays on the instance, so the mechanic will be re-applied if the instance is re-tagged or Apply is called again; use Mechanic:Revoke to also remove the tag.

Show raw api
{
    "functions": [
        {
            "name": "new",
            "desc": "Constructs a new AppliedMechanic for `instance`, registers it in `mechanic.Applications`,\nattaches its Trove to the instance and fires `mechanic.InstanceAdded`. Called by\n`Mechanic:Apply`; you should not need to call it directly because it skips the duplicate check\nand does not add the tag.",
            "params": [
                {
                    "name": "mechanic",
                    "desc": "The mechanic being applied.",
                    "lua_type": "Mechanic<T>"
                },
                {
                    "name": "instance",
                    "desc": "The instance to apply it to.",
                    "lua_type": "Instance"
                },
                {
                    "name": "data",
                    "desc": "Initial `Data`; defaults to a shallow copy of `mechanic.Shared`.",
                    "lua_type": "T?"
                }
            ],
            "returns": [
                {
                    "desc": "The new applied mechanic.",
                    "lua_type": "AppliedMechanic<T>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 236,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "GetData",
            "desc": "Returns the per-instance data associated with this applied mechanic (the same table as\nthe `Data` field).",
            "params": [],
            "returns": [
                {
                    "desc": "The per-instance data.",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 278,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "GetShared",
            "desc": "Returns the shared table inherited from the Mechanic config. It is shared by every instance\nof the mechanic, so changes here affect all of them.",
            "params": [],
            "returns": [
                {
                    "desc": "The Mechanic's shared table.",
                    "lua_type": "T"
                }
            ],
            "function_type": "method",
            "source": {
                "line": 290,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "Destroy",
            "desc": "Cleans the Trove, removes the instance from the Mechanic's `Applications` and fires\n`InstanceRemoved`. The tag stays on the instance, so the mechanic will be re-applied if the\ninstance is re-tagged or `Apply` is called again; use `Mechanic:Revoke` to also remove the tag.",
            "params": [],
            "returns": [],
            "function_type": "method",
            "source": {
                "line": 302,
                "path": "packages/src/Mechanic/init.luau"
            }
        }
    ],
    "properties": [
        {
            "name": "Instance",
            "desc": "The instance this mechanic is applied to.",
            "lua_type": "Instance",
            "readonly": true,
            "source": {
                "line": 182,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "Mechanic",
            "desc": "The Mechanic that created this object.",
            "lua_type": "Mechanic<T>",
            "readonly": true,
            "source": {
                "line": 188,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "Shared",
            "desc": "The Mechanic's shared table (the same table for every instance).",
            "lua_type": "T",
            "readonly": true,
            "source": {
                "line": 194,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "Data",
            "desc": "Per-instance data. A shallow copy of `Shared`, the `data` passed to `Apply`, or the object built by `newConstructor` / `bindToClass`.",
            "lua_type": "T",
            "source": {
                "line": 199,
                "path": "packages/src/Mechanic/init.luau"
            }
        },
        {
            "name": "Trove",
            "desc": "A Trove extended from the Mechanic's Trove. It is cleaned when the instance is destroyed, untagged, leaves the allowed ancestors, or `Destroy` is called; put per-instance connections in it.",
            "lua_type": "Trove",
            "source": {
                "line": 204,
                "path": "packages/src/Mechanic/init.luau"
            }
        }
    ],
    "types": [],
    "name": "AppliedMechanic",
    "desc": "The object a [Mechanic](/api/Mechanic) creates for each instance it is applied to. You get\none from [Mechanic:Apply](/api/Mechanic#Apply), [Mechanic:GetApplied](/api/Mechanic#GetApplied)\nor as the second argument of [Mechanic:OnAdded](/api/Mechanic#OnAdded). Do not construct it\nyourself; use `Mechanic:Apply` instead.\n\nIt owns a `Trove` that is cleaned (and the instance removed from the Mechanic) when the\ninstance is destroyed, leaves the allowed `Ancestors`, or is revoked. Its `Data` field starts as\na shallow copy (`table.clone`) of the Mechanic's `Shared` table unless data was passed to\n`Apply`, and `newConstructor` / `bindToClass` replace it with the constructed object.\n\n```lua\nlocal applied = Spinner:GetApplied(workspace.Windmill)\nif applied then\n\tapplied:GetData().Speed = 10\n\tapplied.Trove:Add(function() print(\"cleaned\") end)\nend\n```\n\nThis package is no longer maintained; see the deprecation notice on [Mechanic](/api/Mechanic).",
    "deprecated": {
        "version": "v1.0.0",
        "desc": "Part of the deprecated Mechanic package; use [Binder](/api/Binder) instead."
    },
    "source": {
        "line": 86,
        "path": "packages/src/Mechanic/init.luau"
    }
}