Defining types
Types are defined in a folder where both the client and server have access to them (i.e. ReplicatedStorage/types).
That way both the client and the server will be able to add your custom defined types to the registry.
In order to define a type, you should use TypeBuilder.
This is a helper class to make defining types easier.
TypeBuilder will create a TypeOptions for you, using the values you provide to each method.
This object is used to register the type.
import { BaseRegistry, TransformResult, TypeBuilder } from "@rbxts/centurion";import { t } from "@rbxts/t";
const playerType = TypeBuilder.create<Player>("player").transform((text, executor) => { if (text === "@me") { return TransformResult.ok(executor); }
const player = Players.FindFirstChild(text); if (player === undefined || !classIs(player, "Player")) { return TransformResult.err("Player not found"); } return TransformResult.ok(player);}).suggestions(() => Players.GetPlayers().map((player) => player.Name)).build();
export = (registry: BaseRegistry) => {registry.registerType(playerType);}The string you provide to TypeBuilder.create will be the name of the type.
It may be useful to store your type names in an enum or constant to make them
more accessible - see CenturionType
for an example.
Methods
-
transform: Takes a function that receives the argument text and the executor of the command and returns a
TransformResult. -
suggestions: Optional, takes a function that returns an array of strings.