ScriptEditorService

แสดงที่เลิกใช้งานแล้ว

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

ไม่สามารถสร้าง
บริการ
ไม่ซ้ำ

บริการนี้ใช้สำหรับการโต้ตอบกับตัวอย่าง ScriptDocument

สรุป

วิธีการ

  • การรักษาความปลอดภัยของปลั๊กอิน

    ลบคอลเลกชันที่ลงทะเบียนไว้ก่อนหน้านี้ที่มีชื่อ name

  • การรักษาความปลอดภัยของปลั๊กอิน

    ลบคอลเลกชันที่ลงทะเบียนไว้ก่อนหน้านี้ที่มีชื่อ name

  • การรักษาความปลอดภัยของปลั๊กอิน

    คืนค่าเปิด ScriptDocument ที่ตรงกับที่ให้ไว้ LuaSourceContainer หรือ nil หากสคริปต์ที่ให้ไว้ไม่เปิด

  • การรักษาความปลอดภัยของปลั๊กอิน

    ส่งคืนแหล่งเวลาแก้ไขสำหรับสคริปต์ที่กำหนด

  • GetScriptDocuments():Instances
    การรักษาความปลอดภัยของปลั๊กอิน

    ส่งคืนคอลเลกชันของเอกสารสคริปต์ที่เปิดอยู่ในปัจจุบันรวมถึงแถบคําสั่ง

  • RegisterAutocompleteCallback(name : string,priority : number,callbackFunction : function):()
    การรักษาความปลอดภัยของปลั๊กอิน

    ลงทะเบียนการโทรกลับอัตโนมัติสำเร็จ callbackFunction ชื่อ name ด้วยลําดับความสําคัญ priority

  • RegisterScriptAnalysisCallback(name : string,priority : number,callbackFunction : function):()
    การรักษาความปลอดภัยของปลั๊กอิน

    ลงทะเบียนการโทรกลับการวิเคราะห์สคริปต์ callbackFunction ชื่อ name ด้วย priority

  • ผลตอบแทน
    การรักษาความปลอดภัยของปลั๊กอิน

    คำขอที่เครื่องมือตัวเขียนสคริปต์เปิดสคริปต์ที่ระบุไว้คืน (จริง, ไม่มี) หากคำขอสําเร็จคืน (false, string) หากคำขอล้มเหลวพร้อมกับสตริงที่อธิบายปัญหา

  • ผลตอบแทน
    การรักษาความปลอดภัยของปลั๊กอิน

    สร้างเนื้อหาใหม่จากสคริปต์เก่าและอัปเดตตัวแก้ไขสคริปต์หากเปิดหรือ Script ตัวแก้ไขสคริปต์ถ้าปิด

เหตุการณ์

  • TextDocumentDidChange(document : ScriptDocument,changesArray : Variant):RBXScriptSignal
    การรักษาความปลอดภัยของปลั๊กอิน

    ไฟไหม้เพียงหลังจากการเปลี่ยนแปลง ScriptDocument ครั้ง

  • การรักษาความปลอดภัยของปลั๊กอิน

    ไฟไหม้เพียงก่อนที่วัตถุ ScriptDocument จะถูกทําลายซึ่งเกิดขึ้นทันทีหลังจากที่เครื่องแก้ไขสคริปต์ปิด

  • การรักษาความปลอดภัยของปลั๊กอิน

    ไฟไหม้เพียงหลังจากที่วัตถุ ScriptDocument ถูกสร้างและถูกผูกกับบริการซึ่งเกิดขึ้นทันทีหลังจากที่เครื่องมือตัวแก้ไขสคริปต์เปิด

คุณสมบัติ

วิธีการ

DeregisterAutocompleteCallback

()
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

name: string
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

ScriptEditorService:DeregisterAutocompleteCallback

game.ScriptEditorService:DeregisterAutocompleteCallback("foo")

DeregisterScriptAnalysisCallback

()
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

name: string
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

ScriptEditorService:DeregisterScriptAnalysisCallback

local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:DeregisterScriptAnalysisCallback("foo")

FindScriptDocument

การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ตัวอย่างโค้ด

ScriptDocument:CloseAsync

--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Find the first open script document
for _, document in documents do
-- The Command Bar can't be closed, so don't select it
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Closed {scriptDocument.Name}`)
else
warn(`Failed to close {scriptDocument.Name} because: {err}`)
end
else
print("No open scripts")
end
Connecting to ScriptDocument.ViewportChanged

--!nocheck
--[[
To run:
1. Ensure Output view is open
2. Run the below code in the Command Bar
3. Scroll up and down in the opened Script window
Print statements from the ViewportChanged event will appear in the Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Create text that spans many lines
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Create a script containing the dummy text and open it
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Failed to open script because: {err}`)
return
end
-- Get a reference to the opened script
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Script Viewport Changed - startLine: {startLine}, endLine: {endLine}`)
end
-- Connect the ViewportChanged event to the function above that prints the start and end line of the updated viewport
scriptDocument.ViewportChanged:Connect(onViewportChanged)

GetEditorSource

การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

ค่าเริ่มต้น: ""

ส่งค่ากลับ

GetScriptDocuments

Instances
การรักษาความปลอดภัยของปลั๊กอิน

ส่งค่ากลับ

Instances

ตัวอย่างโค้ด

Print the name of every script

--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- Prints the name of each script
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
end

RegisterAutocompleteCallback

()
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

name: string
ค่าเริ่มต้น: ""
priority: number
ค่าเริ่มต้น: ""
callbackFunction: function
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

บริการตัวแก้ไขสคริปต์: ลงทะเบียนการโทรกลับอัตโนมัติสำหรับตัวแก้ไขสคริปต์บริการตัวแก้ไขสคริปต์: ยกเลิกการลงทะเบียนการโทรกลับอัตโนมัติ

--!โนเช็ค
-- ดำเนินโค้ดต่อไปนี้ในแถบคําสั่ง
local ScriptEditorService = game:GetService("ScriptEditorService")
type Request = {
position: {
line: number,
character: number,
},
textDocument: {
document: ScriptDocument?,
script: LuaSourceContainer?,
},
}
type Response = {
items: {
{
label: string,
kind: Enum.CompletionItemKind?,
tags: { Enum.CompletionItemTag }?,
detail: string?,
documentation: {
value: string,
}?,
overloads: number?,
learnMoreLink: string?,
codeSample: string?,
preselect: boolean?,
textEdit: {
newText: string,
replace: {
start: { line: number, character: number },
["end"]: { line: number, character: number },
},
}?,
}
},
}
local autocompleteCallback = function(request: Request, response: Response): Response
local item = {
label = "foo",
preselect = true,
}
table.insert(response.items, item)
return response
end
ScriptEditorService:RegisterAutocompleteCallback("foo", 1, autocompleteCallback)
-- เพื่อยกเลิกการลงทะเบียนการโทรกลับ ให้รันโค้ดต่อไปนี้ในแถบคําสั่ง
ScriptEditorService:DeregisterAutocompleteCallback("foo")

RegisterScriptAnalysisCallback

()
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

name: string
ค่าเริ่มต้น: ""
priority: number
ค่าเริ่มต้น: ""
callbackFunction: function
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

ตัวอย่างโค้ด

บริการตัวแก้ไขสคริปต์: ลงทะเบียนการวิเคราะห์สคริปต์กลับ

type Request = {
["script"]: LuaSourceContainer,
}
type Response = {
diagnostics: {
{
range: {
start: {
line: number,
character: number,
},
["end"]: {
line: number,
character: number,
},
},
code: string?,
message: string,
severity: Enum.Severity?,
codeDescription: { href: string }?,
}
},
}
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService:RegisterScriptAnalysisCallback("foo", 1, function(Req: Request): Response
local response = {
diagnostics = {},
}
local lineNo = 1
-- ทำซ้ำบรรทัดโดยบรรทัด
for text, newline in Req.script.Source:gmatch("([^\r\n]*)([\r\n]*)") do
local startIndex, endIndex = string.find(text, "Foo")
if startIndex and endIndex then
table.insert(response.diagnostics, {
range = {
["start"] = {
line = lineNo,
character = startIndex,
},
["end"] = {
line = lineNo,
character = endIndex,
},
},
code = "FooFinder",
message = "Foo found here!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\0%0\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)

OpenScriptDocumentAsync

ผลตอบแทน
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

ค่าเริ่มต้น: ""

ส่งค่ากลับ

ตัวอย่างโค้ด

ScriptEditorService:OpenScriptDocumentAsync

--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local Workspace = game:GetService("Workspace")
local newScript = Instance.new("Script")
newScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(newScript)
if success then
print("Opened script document")
else
print(`Failed to open script document: {err}`)
end

UpdateSourceAsync

()
ผลตอบแทน
การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

ค่าเริ่มต้น: ""
callback: function
ค่าเริ่มต้น: ""

ส่งค่ากลับ

()

เหตุการณ์

TextDocumentDidChange

การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

document: ScriptDocument
changesArray: Variant

ตัวอย่างโค้ด

ScriptEditorService.TextDocumentDidChange

--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("Changed", scriptDocument, changes)
end)

TextDocumentDidClose

การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

oldDocument: ScriptDocument

ตัวอย่างโค้ด

ScriptEditorService.TextDocumentDidClose

--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("Closed", scriptDocument)
end)

TextDocumentDidOpen

การรักษาความปลอดภัยของปลั๊กอิน

พารามิเตอร์

newDocument: ScriptDocument

ตัวอย่างโค้ด

ScriptEditorService.TextDocumentDidOpen

--!nocheck
-- Run the following code in the Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidOpen:Connect(function(scriptDocument)
print("Opened", scriptDocument)
end)