Skip to main content

AttributeUtils

Provides utility functions to work with attributes in Roblox

Types

AttributePredicate

type AttributePredicate = (valueany) → boolean

Predicate run against the current value of an attribute.

BinderLike

type BinderLike = {
Bind(
selfany,
instInstance
) → any,
...
}

Subset of the Binder API that AttributeUtils.bindToBinder needs. Declared structurally since this package cannot depend upon the binder package.

Functions

isValidAttributeType

AttributeUtils.isValidAttributeType(valueTypestring) → boolean

Returns whether the attribute is a valid type or not for an attribute.

print(AttributeUtils.isValidAttributeType(typeof("hi"))) --> true

promiseAttribute

AttributeUtils.promiseAttribute(
instanceInstance,
attributeNamestring,
predicateAttributePredicate?,
cancelTokenCancelToken?
) → Promise<unknown>

Promises attribute value fits predicate

bindToBinder

AttributeUtils.bindToBinder(
instanceInstance,
attributeNamestring,
binderBinder<T>
) → Maid

Whenever the attribute is true, the binder will be bound, and when the binder is bound, the attribute will be true.

initAttribute

AttributeUtils.initAttribute(
instanceInstance,
attributeNamestring,
defaultT
) → T--

The value of the attribute

Initializes an attribute for a given instance

getAttribute

AttributeUtils.getAttribute(
instanceInstance,
attributeNamestring,
defaultT
) → T

Retrieves an attribute, and if it is nil, returns the default instead.

removeAllAttributes

AttributeUtils.removeAllAttributes(instanceInstance) → ()

Removes all attributes from an instance.

Show raw api
{
    "functions": [
        {
            "name": "isValidAttributeType",
            "desc": "Returns whether the attribute is a valid type or not for an attribute.\n\n```lua\nprint(AttributeUtils.isValidAttributeType(typeof(\"hi\"))) --> true\n```",
            "params": [
                {
                    "name": "valueType",
                    "desc": "",
                    "lua_type": "string"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "boolean"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 77,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        },
        {
            "name": "promiseAttribute",
            "desc": "Promises attribute value fits predicate",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "predicate",
                    "desc": "",
                    "lua_type": "AttributePredicate?"
                },
                {
                    "name": "cancelToken",
                    "desc": "",
                    "lua_type": "CancelToken?"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Promise<unknown>"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 90,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        },
        {
            "name": "bindToBinder",
            "desc": "Whenever the attribute is true, the binder will be bound, and when the\nbinder is bound, the attribute will be true.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "binder",
                    "desc": "",
                    "lua_type": "Binder<T>"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "Maid"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 143,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        },
        {
            "name": "initAttribute",
            "desc": "Initializes an attribute for a given instance",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "default",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "The value of the attribute",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 208,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        },
        {
            "name": "getAttribute",
            "desc": "Retrieves an attribute, and if it is nil, returns the default\ninstead.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                },
                {
                    "name": "attributeName",
                    "desc": "",
                    "lua_type": "string"
                },
                {
                    "name": "default",
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "returns": [
                {
                    "desc": "",
                    "lua_type": "T"
                }
            ],
            "function_type": "static",
            "source": {
                "line": 229,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        },
        {
            "name": "removeAllAttributes",
            "desc": "Removes all attributes from an instance.",
            "params": [
                {
                    "name": "instance",
                    "desc": "",
                    "lua_type": "Instance"
                }
            ],
            "returns": [],
            "function_type": "static",
            "source": {
                "line": 246,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        }
    ],
    "properties": [],
    "types": [
        {
            "name": "AttributePredicate",
            "desc": "Predicate run against the current value of an attribute.",
            "lua_type": "(value: any) -> boolean",
            "source": {
                "line": 22,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        },
        {
            "name": "BinderLike",
            "desc": "Subset of the [Binder] API that [AttributeUtils.bindToBinder] needs. Declared\nstructurally since this package cannot depend upon the binder package.",
            "lua_type": "{ Bind: (self: any, inst: Instance) -> any, ... }",
            "source": {
                "line": 31,
                "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
            }
        }
    ],
    "name": "AttributeUtils",
    "desc": "Provides utility functions to work with attributes in Roblox",
    "source": {
        "line": 6,
        "path": "src/attributeutils/src/Shared/AttributeUtils.lua"
    }
}