エンジンクラス
ScriptEditorService
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
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):() |
イベント
TextDocumentDidChange(document: ScriptDocument,changesArray: Variant):RBXScriptSignal |
TextDocumentDidClose(oldDocument: ScriptDocument):RBXScriptSignal |
TextDocumentDidOpen(newDocument: ScriptDocument):RBXScriptSignal |
APIリファレンス
方法
DeregisterAutocompleteCallback
DeregisterScriptAnalysisCallback
FindScriptDocument
パラメータ
コードサンプル
ScriptDocument:CloseAsync
--!nocheck
-- 次のコードをコマンドバーで実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- 最初に開いているスクリプトドキュメントを見つける
for _, document in documents do
-- コマンドバーは閉じることができないので、選択しないでください
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`閉じました {scriptDocument.Name}`)
else
warn(`{scriptDocument.Name} を閉じるのに失敗しました: {err}`)
end
else
print("開いているスクリプトはありません")
endScriptDocument.ViewportChanged への接続
--!nocheck
--[[
実行するには:
1. 出力ビューが開いていることを確認します
2. コマンドバーで以下のコードを実行します
3. 開いているスクリプトウィンドウで上下にスクロールします
ViewportChanged イベントからの印刷文は出力に表示されます
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- 複数行にわたるテキストを作成
local dummyText = string.rep("-- ダミーテキスト\n", 60)
-- ダミーテキストを含むスクリプトを作成し、それを開く
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`スクリプトのオープンに失敗しました: {err}`)
return
end
-- 開かれたスクリプトへの参照を取得
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`スクリプトのビューポートが変更されました - 開始行: {startLine}, 終了行: {endLine}`)
end
-- 更新されたビューポートの開始行と終了行を印刷する上記の関数に ViewportChanged イベントを接続
scriptDocument.ViewportChanged:Connect(onViewportChanged)GetEditorSource
パラメータ
戻り値
GetScriptDocuments
戻り値
コードサンプル
すべてのスクリプトの名前を印刷する
--!nocheck
-- コマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local scriptDocuments = ScriptEditorService:GetScriptDocuments()
for _, scriptDocument in scriptDocuments do
-- 各スクリプトの名前を印刷します
if not scriptDocument:IsCommandBar() then
print(scriptDocument.Name)
end
endOpenScriptDocumentAsync
パラメータ
| 既定値: "nil" |
戻り値
コードサンプル
OpenScriptDocumentAsync()
--!nocheck
-- 次のコードをコマンドバーで実行します
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("スクリプトドキュメントを開きました")
else
print(`スクリプトドキュメントを開くのに失敗しました: {err}`)
endRegisterAutocompleteCallback
戻り値
()
コードサンプル
RegisterAutocompleteCallback() および DeregisterAutocompleteCallback()
--!nocheck
-- コマンドバーで以下のコードを実行します。
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
戻り値
()
コードサンプル
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
-- 行ごとに繰り返す
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 が見つかりました!",
severity = Enum.Severity.Warning,
})
end
lineNo = lineNo + #newline:gsub("\n+", "\0%0\0"):gsub(".%z.", "."):gsub("%z", "")
end
return response
end)UpdateSourceAsync
パラメータ
戻り値
()
イベント
TextDocumentDidChange
ScriptEditorService.TextDocumentDidChange(
パラメータ
changesArray:Variant |
コードサンプル
スクリプトエディタサービス.TextDocumentDidChange
--!nocheck
-- コマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidChange:Connect(function(scriptDocument, changes)
print("変更されました", scriptDocument, changes)
end)TextDocumentDidClose
パラメータ
コードサンプル
ScriptEditorService.TextDocumentDidClose
--!nocheck
-- 次のコードをコマンドバーで実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
ScriptEditorService.TextDocumentDidClose:Connect(function(scriptDocument)
print("閉じました", scriptDocument)
end)TextDocumentDidOpen
パラメータ
コードサンプル
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)