ScriptEditorService

Pokaż przestarzałe

*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.

Brak możliwości tworzenia
Usługa
Bez replikacji

Ta usługa jest używana do wchodzenia w interakcję z instancjami ScriptDocument.

Podsumowanie

Metody

Zdarzenia

Właściwości

Metody

DeregisterAutocompleteCallback

()
Zabezpieczenia dodatku plug-in

Parametry

name: string
Wartość domyślna: ""

Zwroty

()

Przykłady kodu

ScriptEditorService:DeregisterAutocompleteCallback

game.ScriptEditorService:DeregisterAutocompleteCallback("foo")

DeregisterScriptAnalysisCallback

()
Zabezpieczenia dodatku plug-in

Parametry

name: string
Wartość domyślna: ""

Zwroty

()

Przykłady kodu

ScriptEditorService:DeregisterScriptAnalysisCallback

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

FindScriptDocument

Zabezpieczenia dodatku plug-in

Parametry

Wartość domyślna: ""

Zwroty

Przykłady kodu

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

Zabezpieczenia dodatku plug-in

Parametry

Wartość domyślna: ""

Zwroty

GetScriptDocuments

Instances
Zabezpieczenia dodatku plug-in

Zwroty

Instances

Przykłady kodu

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

()
Zabezpieczenia dodatku plug-in

Parametry

name: string
Wartość domyślna: ""
priority: number
Wartość domyślna: ""
callbackFunction: function
Wartość domyślna: ""

Zwroty

()

Przykłady kodu

ScriptEditorService:RegisterAutocompleteCallback Usługa edytora skryptów: Odinstaluj usługę Autokompletowania

--!noczekuj
-- Wykonaj następujący kod w pasku poleceń
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)
-- Aby odrejestrować powiadomienie o wywołaniu, wykonaj następujący kod w pasku poleceń
ScriptEditorService:DeregisterAutocompleteCallback("foo")

RegisterScriptAnalysisCallback

()
Zabezpieczenia dodatku plug-in

Parametry

name: string
Wartość domyślna: ""
priority: number
Wartość domyślna: ""
callbackFunction: function
Wartość domyślna: ""

Zwroty

()

Przykłady kodu

ScriptEditorService: Rejestracja analizy skryptów

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
-- Powtarzaj linię po linii
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

Wynik
Zabezpieczenia dodatku plug-in

Parametry

Wartość domyślna: ""

Zwroty

Przykłady kodu

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

()
Wynik
Zabezpieczenia dodatku plug-in

Parametry

Wartość domyślna: ""
callback: function
Wartość domyślna: ""

Zwroty

()

Zdarzenia

TextDocumentDidChange

Zabezpieczenia dodatku plug-in

Parametry

document: ScriptDocument
changesArray: Variant

Przykłady kodu

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

Zabezpieczenia dodatku plug-in

Parametry

oldDocument: ScriptDocument

Przykłady kodu

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

Zabezpieczenia dodatku plug-in

Parametry

newDocument: ScriptDocument

Przykłady kodu

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)