Motor Sınıfı
ScriptEditorService
*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.
Özet
Yöntemler
DeregisterAutocompleteCallback(name: string):() |
DeregisterScriptAnalysisCallback(name: string):() |
GetEditorSource(script: LuaSourceContainer):string |
OpenScriptDocumentAsync(script: LuaSourceContainer,options: Dictionary):Tuple |
RegisterAutocompleteCallback(name: string,priority: number,callbackFunction: function):() |
RegisterScriptAnalysisCallback(name: string,priority: number,callbackFunction: function):() |
UpdateSourceAsync(script: LuaSourceContainer,callback: function):() |
Olaylar
TextDocumentDidChange(document: ScriptDocument,changesArray: Variant):RBXScriptSignal |
TextDocumentDidClose(oldDocument: ScriptDocument):RBXScriptSignal |
TextDocumentDidOpen(newDocument: ScriptDocument):RBXScriptSignal |
API Referansı
Yöntemler
DeregisterAutocompleteCallback
Parametreler
Dönüşler
()
Kod Örnekleri
DeregisterAutocompleteCallback()
local ScriptEditorService = game:GetService("ScriptEditorService")
-- "foo" için otomatik tamamlamayı iptal et
ScriptEditorService:DeregisterAutocompleteCallback("foo")DeregisterScriptAnalysisCallback
FindScriptDocument
Parametreler
Dönüşler
Kod Örnekleri
ScriptDocument:CloseAsync
`--!nocheck`
`-- Aşağıdaki kodu Komut Çubuğunda çalıştırın`
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
`-- İlk açık script belgesini bul`
for _, document in documents do
`-- Komut Çubuğu kapatılamaz, bu yüzden onu seçmeyin`
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Kapandı {scriptDocument.Name}`)
else
warn(`Kapatılamadı {scriptDocument.Name} çünkü: {err}`)
end
else
print("Açık script yok")
endScriptDocument.ViewportChanged'e Bağlanıyor
--!nocheck
--[[
Çalıştırmak için:
1. Çıkış görünümünün açık olduğundan emin olun
2. Aşağıdaki kodu Komut Çubuğu'nda çalıştırın
3. Açılan Script penceresinde yukarı ve aşağı kaydırın
ViewportChanged olayından yazdırma ifadeleri Çıkış'ta görünecektir
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Birçok satırı kapsayan metin oluşturun
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Dummy metni içeren bir script oluşturun ve açın
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Script açılmadı çünkü: {err}`)
return
end
-- Açılan script'e referans alın
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Script Görüntü Alanı Değişti - başlangıç Satırı: {startLine}, bitiş Satırı: {endLine}`)
end
-- Yukarıdaki fonksiyonu görüntü alanının güncellenmiş başlangıç ve bitiş satırını yazdıracak şekilde ViewportChanged olayına bağlayın
scriptDocument.ViewportChanged:Connect(onViewportChanged)GetEditorSource
Parametreler
Dönüşler
GetScriptDocuments
Dönüşler
Kod Örnekleri
Her bir scriptin adını yazdır
--!nocheck
-- Aşağıdaki kodu Komut Çubuğunda çalıştırın
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- Her bir scriptin adını yazdırır
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
endOpenScriptDocumentAsync
Parametreler
| Varsayılan değer: "nil" |
Dönüşler
Kod Örnekleri
OpenScriptDocumentAsync()
--!nocheck
-- Aşağıdaki kodu Komut Çubuğunda çalıştırın
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("Betik belgesi açıldı")
else
print(`Betik belgesi açılamadı: {err}`)
endRegisterAutocompleteCallback
Dönüşler
()
Kod Örnekleri
RegisterAutocompleteCallback() ve DeregisterAutocompleteCallback()
--!nocheck
-- Aşağıdaki kodu Komut Çubuğu'nda çalıştırın
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)
-- Callback'i kaldırmak için, aşağıdaki kodu Komut Çubuğu'nda çalıştırın
ScriptEditorService:DeregisterAutocompleteCallback("foo")RegisterScriptAnalysisCallback
Dönüşler
()
Kod Örnekleri
RegisterScriptAnalysisCallback()
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
-- Satır satır dolaş
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 burada bulundu!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\\0%0\\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)UpdateSourceAsync
Parametreler
Dönüşler
()
Olaylar
TextDocumentDidChange
ScriptEditorService.TextDocumentDidChange(
Parametreler
changesArray:Variant |
Kod Örnekleri
ScriptEditorService.TextDocumentDidChange
--!nocheck
-- Aşağıdaki kodu Komut Çubuğunda çalıştırın
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("Değiştirildi", scriptDocument, changes)
end)TextDocumentDidClose
Parametreler
Kod Örnekleri
ScriptEditorService.MetinDokümanKapatıldı
--!nocheck
-- Aşağıdaki kodu Komut Çubuğunda çalıştırın
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("Kapandı", scriptDocument)
end)TextDocumentDidOpen
Parametreler
Kod Örnekleri
ScriptEditorService.MetinBelgeAçıldı
--!nocheck
-- Aşağıdaki kodu Komut Çubuğu'nda çalıştırın
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidOpen:Connect(function(scriptDocument)
print("Açıldı", scriptDocument)
end)