debug

*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.


Tóm tắt

Chức Năng
traceback(message: string,level: number):string
traceback(thread: coroutine,message: string,level: number):string
info(level: number,options: string):Tuple
info(function: function,options: string):Tuple
info(thread: coroutine,level: number,options: string):Tuple
profilebegin(label: string):()

Tài Liệu Tham Khảo API
Chức Năng
traceback
debug.traceback(
message:string, level:number
Tham Số
message:string
level:number
Giá Trị Mặc Định: 1
Lợi Nhuận
Mẫu mã
Theo dõi gỡ lỗi

traceback
debug.traceback(
thread:coroutine, message:string, level:number
Tham Số
thread:coroutine
message:string
level:number
Giá Trị Mặc Định: 1
Lợi Nhuận
Mẫu mã
Theo Dõi Lỗi Của Một Luồng

info
debug.info(
level:number, options:string
Tham Số
level:number
options:string
Lợi Nhuận
Mẫu mã
Thông Tin Gỡ Lỗi Theo Cấp

info
debug.info(
function:function, options:string
Tham Số
function:function
options:string
Lợi Nhuận
Mẫu mã
Thông tin gỡ lỗi theo hàm

info
debug.info(
thread:coroutine, level:number, options:string
Tham Số
thread:coroutine
level:number
options:string
Lợi Nhuận
Mẫu mã
Thông tin gỡ lỗi theo luồng

profilebegin
debug.profilebegin(label:string):()
Tham Số
label:string
Lợi Nhuận
()
Mẫu mã
Bắt đầu Ghi Nhận Lỗi
local function buildGrid(size)
debug.profilebegin("Xây Dựng Lưới")
local grid = table.create(size * size, 0)
debug.profileend()
return grid
end
print(#buildGrid(32)) --> 1024

profileend
debug.profileend():()
Lợi Nhuận
()
Mẫu mã
Kết thúc Hồ Sơ Gỡ Lỗi
debug.profilebegin("Outer")
debug.profilebegin("Inner")
-- Công việc thực hiện ở đây được tính thời gian dưới cả hai nhãn
debug.profileend() -- đóng "Inner"
debug.profileend() -- đóng "Outer"

getmemorycategory
debug.getmemorycategory():string
Lợi Nhuận
Mẫu mã
Gỡ lỗi Lấy Danh Mục Bộ Nhớ
local category = debug.getmemorycategory()
print(type(category)) --> string
-- Danh mục theo luồng, vì vậy một cái mới có thể khác với cái này
local previous = debug.setmemorycategory("Pathfinding")
print(debug.getmemorycategory()) --> Pathfinding
debug.setmemorycategory(previous)

setmemorycategory
debug.setmemorycategory(tag:string):string
Tham Số
tag:string
Lợi Nhuận
Mẫu mã
Danh mục bộ nhớ gỡ lỗi
local original = debug.setmemorycategory("MapGeneration")
print(debug.getmemorycategory()) --> MapGeneration
-- Các phân bổ được thực hiện ở đây sẽ được liệt kê dưới "MapGeneration" trong Bảng điều khiển Nhà phát triển
local tiles = table.create(1000, 0)
-- Giá trị trả về là danh mục trước đó, vì vậy nó có thể được khôi phục
print(debug.setmemorycategory(original) == "MapGeneration") --> true
print(#tiles) --> 1000

resetmemorycategory
debug.resetmemorycategory():()
Lợi Nhuận
()
Mẫu mã
Danh mục Đặt lại Bộ nhớ Gỡ lỗi
local automatic = debug.getmemorycategory()
debug.setmemorycategory("Đang Tạo")
print(debug.getmemorycategory()) --> Đang Tạo
debug.resetmemorycategory()
print(debug.getmemorycategory() == automatic) --> true

dumpcodesize
debug.dumpcodesize():()
Lợi Nhuận
()
Mẫu mã
Kích thước mã Debug Dump
-- debug.dumpcodesize() chỉ hoạt động từ Command Bar trong Studio, nơi nó in ra một
-- báo cáo đến Output với một bảng cho mỗi kịch bản gốc, các hàm lớn nhất trước:
-- # Phân tích Kích thước Mã Gốc
-- <n> kịch bản, <n> hàm, <n> KB bộ nhớ, giới hạn kích thước mã 256 MB
-- ## <tên kịch bản>
-- <n> hàm, <n> KB bộ nhớ
-- | Hàm | Dòng | Kích thước Mã Gốc | Kích thước Mã Gốc (%) |
-- Chỉ các kịch bản bắt đầu bằng --!native và đã chạy mới xuất hiện trong báo cáo.
-- Từ một Kịch bản, nó sẽ phát sinh một lỗi, mà pcall sẽ bắt
local ok, message = pcall(debug.dumpcodesize)
print(ok) --> false
print(message) --> dumpcodesize chỉ có thể được gọi từ CommandBar

©2026 Roblox Corporation. Roblox, logo Roblox và Powering Imagination là các nhãn hiệu đã đăng ký và chưa đăng ký của chúng tôi tại Hoa Kỳ và các quốc gia khác.