Your First Character
Characters is another name for a component, which you can attach to an instance by giving it a tag. It is essentially the same as creating a class and binding it to a CollectionService tag.
What is a Character?
A Character is synonymous with a component or an instance-attached class. Instead of creating a metatable and then defining an instance for it, Characters simplify this process by automatically assigning themselves to a given tag. You can then treat it as if it was a regular luau class by adding functions to the Character.
Writing a Character
Every book needs its own characters! Here is how you might write your own Character for your workflow:
-- "init" is a lifecycle hook that always runs first!
local function init(self) -- "self" passes an instance attached to the tag.
print("Character is attached to " .. self.instance:GetFullName())
end
-- "destroy" is a lifecycle hook that runs on the instance being removed.
local function destroy(self)
print("Character " .. self.instance:GetFullName() .. " has been destroyed!")
end
return {
tag = "Example_Tag", -- This Character now binds to any instance with this tag.
init = init,
destroy = destroy,
}
If you did everything correctly, this should now print the full names of any instance that has the Example_Tag tag.
Using a Character
WARNING ― As of right now, getting a Character from its instance is not possible with Quill. This is, however, an intended feature of Quill and will most likely come out in version 0.2.0-alpha.
Summary
Characters are components that provide functions to tagged instances.
Lifecycle hooks are automatically called on runtime, allowing Characters to run automatically and independently.
Last updated