跳至正文
版本:latest - a1.147.x ⚖️

🔤 控制台

提供注册控制台命令和记录日志消息的功能。

🗿Static Class
This is a Static Class. Access it's methods directly with .. It's not possible to spawn new instances.
💂Authority
This static class can be accessed on both 🟧 Client and 🟦 Server side.
🧑‍💻API Source
This page is auto-generated! The Functions, Properties and Events described here are defined in our GitHub's API Repository! Feel free to commit suggestions and changes to the source .json API files!

🎒 示例

(Console.Log) Basic
Console.Log("Hello, world!")
-- Outputs "Hello, world!"
(Console.Log) With formatting (string)
local player_name = "John"
Console.Log("Hello %s!", player_name)
-- Outputs "Hello John!"
(Console.Log) With formatting (integer)
local health = 50
local max_health = 100
Console.Log("Player health: %d/%d", health, max_health)
-- Outputs "Player health: 50/100"
(Console.RegisterCommand) Registering to a command that sends a message to everyone
Console.RegisterCommand("hello", function(text)
Console.Log("Sending a 'Hello %s' to everyone!", text)
Chat.BroadcastMessage("Hello " .. text)
end, "says a message to everyone", { "my_text" })
(Console.RunCommand) Running a Console Command
Console.RunCommand("hello")
(Console "PlayerSubmit" Event) Handles Console Inputs
Console.Subscribe("PlayerSubmit", function(text)
if (text == "some_text") then
Console.Log("Player submitted some_text!")
end
end)

🗿 静态函数

ReturnsNameDescription
Debug在控制台中记录一条调试消息,支持参数格式化。仅当当前日志级别为 Debug 或 Verbose 时输出
Error在控制台中记录一条带有堆栈信息的红色错误消息
Log在控制台中记录并格式化一条消息
RegisterCommand注册一个新的控制台命令
RunCommand通过编程方式运行一个控制台命令(只有通过脚本注册的命令才能被触发)
Warn在控制台中记录一条带有堆栈信息的橙色警告消息

Debug

在控制台中记录一条调试消息,支持参数格式化。仅当当前日志级别为 Debug 或 Verbose 时输出
Console.Debug(message, args...?)

Parameters

TypeParameterDefaultDescription
stringmessage Required parameter 要打印的消息
anyargs...?nil其他用于通过 string.format 格式化消息的参数

Error

在控制台中记录一条带有堆栈信息的红色错误消息,支持参数格式化
Console.Error(message, args...?)

Parameters

TypeParameterDefaultDescription
stringmessage Required parameter 要打印的消息
anyargs...?nil其他用于通过 string.format 格式化消息的参数

Log

在控制台中记录并格式化一条消息,支持参数格式化
Console.Log(message, args...?)

Parameters

TypeParameterDefaultDescription
stringmessage Required parameter 要打印的消息
anyargs...?nil其他用于通过 string.format 格式化消息的参数
Console.Log Examples
Basic
Console.Log("Hello, world!")
-- Outputs "Hello, world!"
With formatting (string)
local player_name = "John"
Console.Log("Hello %s!", player_name)
-- Outputs "Hello John!"
With formatting (integer)
local health = 50
local max_health = 100
Console.Log("Player health: %d/%d", health, max_health)
-- Outputs "Player health: 50/100"

RegisterCommand

注册一个新的控制台命令
Console.RegisterCommand(command, callback, description?, parameters?)

Parameters

TypeParameterDefaultDescription
stringcommand Required parameter 命令
functioncallback Required parameter 当输入该命令时需要调用的回调函数 with this format
stringdescription?要在控制台中显示的命令描述
table of stringparameters?{}要在控制台中显示的受支持参数列表
Console.RegisterCommand Examples
Registering to a command that sends a message to everyone
Console.RegisterCommand("hello", function(text)
Console.Log("Sending a 'Hello %s' to everyone!", text)
Chat.BroadcastMessage("Hello " .. text)
end, "says a message to everyone", { "my_text" })

RunCommand

通过编程方式运行一个控制台命令(只有通过脚本注册的命令才能被触发)
Console.RunCommand(command)

Parameters

TypeParameterDefaultDescription
stringcommand Required parameter 命令
Console.RunCommand Examples
Running a Console Command
Console.RunCommand("hello")

Warn

在控制台中记录一条带有堆栈信息的橙色警告消息,支持参数格式化
Console.Warn(message, args...?)

Parameters

TypeParameterDefaultDescription
stringmessage Required parameter 要打印的消息
anyargs...?nil其他用于通过 string.format 格式化消息的参数

🚀 事件

NameDescription
LogEntry当收到一条日志时调用
PlayerSubmit当提交控制台命令时调用

LogEntry

当收到一条日志时调用
Console.Subscribe("LogEntry", function(text, type)
-- LogEntry was called
end)

Arguments

TypeArgumentDescription
stringtext日志消息
LogTypetype日志的类型

PlayerSubmit

当提交控制台命令时调用
Console.Subscribe("PlayerSubmit", function(text)
-- PlayerSubmit was called
end)

Arguments

TypeArgumentDescription
stringtext提交的文本
Console "PlayerSubmit" Event Examples
Handles Console Inputs
Console.Subscribe("PlayerSubmit", function(text)
if (text == "some_text") then
Console.Log("Player submitted some_text!")
end
end)