debug

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


ข้อมูลสรุป

ฟังก์ชัน
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):()

เอกสารอ้างอิงเกี่ยวกับ API
ฟังก์ชัน
traceback
debug.traceback(
message:string, level:number
พารามิเตอร์
message:string
level:number
ค่าเริ่มต้น: 1
ส่งค่ากลับ
ตัวอย่างโค้ด
การติดตามข้อผิดพลาด

traceback
debug.traceback(
thread:coroutine, message:string, level:number
พารามิเตอร์
thread:coroutine
message:string
level:number
ค่าเริ่มต้น: 1
ส่งค่ากลับ
ตัวอย่างโค้ด
การติดตามข้อผิดพลาดของเธรด

info
debug.info(
level:number, options:string
พารามิเตอร์
level:number
options:string
ส่งค่ากลับ
ตัวอย่างโค้ด
ข้อมูลการดีบักตามระดับ

info
debug.info(
function:function, options:string
พารามิเตอร์
function:function
options:string
ส่งค่ากลับ
ตัวอย่างโค้ด
ข้อมูลการดีบักตามฟังก์ชัน

info
debug.info(
thread:coroutine, level:number, options:string
พารามิเตอร์
thread:coroutine
level:number
options:string
ส่งค่ากลับ
ตัวอย่างโค้ด
ข้อมูลการดีบักตามเธรด

profilebegin
debug.profilebegin(label:string):()
พารามิเตอร์
label:string
ส่งค่ากลับ
()
ตัวอย่างโค้ด
เริ่มต้นโปรไฟล์ดีบัก
local function buildGrid(size)
debug.profilebegin("สร้างกริด")
local grid = table.create(size * size, 0)
debug.profileend()
return grid
end
print(#buildGrid(32)) --> 1024

profileend
debug.profileend():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
สิ้นสุดโปรไฟล์ดีบัก
debug.profilebegin("Outer")
debug.profilebegin("Inner")
-- งานที่ทำที่นี่จะถูกจับเวลาใต้ป้ายทั้งสอง
debug.profileend() -- ปิด "Inner"
debug.profileend() -- ปิด "Outer"

getmemorycategory
debug.getmemorycategory():string
ส่งค่ากลับ
ตัวอย่างโค้ด
การดีบักการดึงหมวดหมู่หน่วยความจำ
local category = debug.getmemorycategory()
print(type(category)) --> string
-- หมวดหมู่จะติดตามเธรด ดังนั้นหมวดหมู่ใหม่อาจแตกต่างจากหมวดหมู่นี้
local previous = debug.setmemorycategory("Pathfinding")
print(debug.getmemorycategory()) --> Pathfinding
debug.setmemorycategory(previous)

setmemorycategory
debug.setmemorycategory(tag:string):string
พารามิเตอร์
tag:string
ส่งค่ากลับ
ตัวอย่างโค้ด
การตั้งค่าหมวดหมู่หน่วยความจำสำหรับการดีบัก
local original = debug.setmemorycategory("MapGeneration")
print(debug.getmemorycategory()) --> MapGeneration
-- การจัดสรรที่ทำที่นี่จะถูกระบุไว้ภายใต้ "MapGeneration" ใน Developer Console
local tiles = table.create(1000, 0)
-- ค่าที่ส่งกลับคือหมวดหมู่ก่อนหน้า ดังนั้นจึงสามารถกู้คืนได้
print(debug.setmemorycategory(original) == "MapGeneration") --> true
print(#tiles) --> 1000

resetmemorycategory
debug.resetmemorycategory():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
รีเซ็ตหมวดหน่วยความจำสำหรับการดีบัก
local automatic = debug.getmemorycategory()
debug.setmemorycategory("การสร้าง")
print(debug.getmemorycategory()) --> การสร้าง
debug.resetmemorycategory()
print(debug.getmemorycategory() == automatic) --> true

dumpcodesize
debug.dumpcodesize():()
ส่งค่ากลับ
()
ตัวอย่างโค้ด
ขนาดโค้ด Debug Dump
-- debug.dumpcodesize() ใช้งานได้เฉพาะจาก Studio Command Bar ซึ่งจะพิมพ์
-- รายงานไปยัง Output โดยมีตารางหนึ่งตารางต่อสคริปต์เนทีฟ ฟังก์ชันที่ใหญ่ที่สุดก่อน:
-- # การวิเคราะห์ขนาดโค้ดเนทีฟ
-- <n> สคริปต์, <n> ฟังก์ชัน, <n> KB หน่วยความจำ, ขนาดโค้ดจำกัด 256 MB
-- ## <ชื่อสคริปต์>
-- <n> ฟังก์ชัน, <n> KB หน่วยความจำ
-- | ฟังก์ชัน | บรรทัด | ขนาดโค้ดเนทีฟ | ขนาดโค้ดเนทีฟ (%) |
-- สคริปต์ที่เริ่มต้นด้วย --!native และได้ทำงานจะปรากฏในรายงาน.
-- จากสคริปต์จะเกิดข้อผิดพลาด ซึ่ง pcall จะจับ
local ok, message = pcall(debug.dumpcodesize)
print(ok) --> false
print(message) --> dumpcodesize สามารถเรียกใช้ได้เฉพาะจาก CommandBar

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ