Type@ember/commands
commands.CommandArg
One argument of a command, read from what the player typed.
Example
local commands = require("@ember/commands")
local players = require("@ember/players")
-- Every argument kind. Each is required and typed in this order: `/announce 3 0.5 red Hello all`.
-- A typed local keeps each `kind` a kind under strict mode.
local announceArgs: { commands.CommandArg } = {
-- A whole number; `min` and `max` bound it.
{ name = "times", kind = "integer", min = 1, max = 5 },
-- Any number, decimals included.
{ name = "gap", kind = "number", min = 0.1, max = 10 },
-- One word, up to the next space.
{ name = "color", kind = "word" },
-- The rest of the line, spaces included, so it must come last.
{ name = "message", kind = "text" },
}
commands.register("announce", {
description = "Broadcast a message a few times",
args = announceArgs,
-- Players' text goes out as MiniMessage, so keep this one to admins.
dev = true,
run = function(sender, args)
local times: number, gap: number = args.times, args.gap
local color: string, message: string = args.color, args.message
-- `run` may yield: the waits pause only this command.
for _ = 1, times do
for _, player in players.all() do
player:send(`<{color}>[{sender.name}] {message}`)
end
task.wait(gap)
end
end,
})Fields
commandArg.kind: "word" | "text" | "integer" | "number" | "player""word"; "text", the rest of the line, so it comes last; "integer"; "number"; or "player", a player in this instance by name
commandArg.max: number?the largest integer or number taken
commandArg.min: number?the smallest integer or number taken
commandArg.name: stringthe key it has in the table run gets