エンジンクラス
ScriptDocument
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
MultiEditTextAsync(edits: {any}):Tuple |
イベント
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal |
ViewportChanged(startLine: number,endLine: number):RBXScriptSignal |
APIリファレンス
方法
CloseAsync
戻り値
コードサンプル
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("開いているスクリプトはありません")
endEditTextAsync
ForceSetSelectionAsync
戻り値
コードサンプル
スクリプト文書: ForceSetSelectionAsync()
--!nocheck
-- スクリプトが開いている間にコマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
-- カーソルの現在の行のテキストを取得します
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- テキストの全行を強制的に選択します
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("選択が設定されました!")
else
print(`選択の設定に失敗しました: {err}`)
end
else
print("スクリプトが開いていません")
endGetLine
パラメータ
| 既定値: "nil" |
戻り値
コードサンプル
ScriptDocument.SelectionChanged と ScriptDocument:GetLine()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectionChanged:Connect(function(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`選択された: 行 {positionLine}, 文字 {positionCharacter}`)
print(`アンカー: 行 {anchorLine}, 文字 {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`選択された行のテキスト: {lineText}`)
end)
else
print("スクリプトが開いていません")
endGetLineCount
戻り値
コードサンプル
スクリプトドキュメント:GetLineCount()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local lineCount = scriptDocument:GetLineCount()
print(`スクリプトは {lineCount} 行あります!`)
else
print("開いているスクリプトはありません")
endGetScript
コードサンプル
ScriptDocument:GetScript()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local openScript = scriptDocument:GetScript()
print(`現在開いているスクリプト: {openScript:GetFullName()}`)
else
print("スクリプトが開いていません")
endGetSelectedText
戻り値
コードサンプル
ScriptDocument:HasSelectedText() と :GetSelectedText()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで以下のコードを実行してください
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectionChanged:Connect(function()
if scriptDocument:HasSelectedText() then
local selectedText = scriptDocument:GetSelectedText()
print(`現在選択されているテキスト: {selectedText}`)
else
print("現在選択されているテキストはありません")
end
end)
else
print("スクリプトは開いていません")
endGetSelectionEnd
戻り値
コードサンプル
ScriptDocument:GetSelectionStart() と :GetSelectionEnd()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local startLine, startCharacter = scriptDocument:GetSelectionStart()
local endLine, endCharacter = scriptDocument:GetSelectionEnd()
print(`選択開始: 行 {startLine}, 文字 {startCharacter}`)
print(`選択終了: 行 {endLine}, 文字 {endCharacter}`)
else
print("スクリプトは開いていません")
endGetSelectionStart
戻り値
コードサンプル
ScriptDocument:GetSelectionStart() と :GetSelectionEnd()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local startLine, startCharacter = scriptDocument:GetSelectionStart()
local endLine, endCharacter = scriptDocument:GetSelectionEnd()
print(`選択開始: 行 {startLine}, 文字 {startCharacter}`)
print(`選択終了: 行 {endLine}, 文字 {endCharacter}`)
else
print("スクリプトは開いていません")
endGetText
戻り値
コードサンプル
スクリプトドキュメント:GetText()
--!nocheck
-- スクリプトが開いている状態でコマンドバーに以下のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local text = scriptDocument:GetText()
print(`スクリプトの内容: {text}`)
else
print("スクリプトは開いていません")
endGetViewport
戻り値
コードサンプル
ScriptDocument:GetViewport
--!nocheck
-- スクリプトが開いている間にコマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
local firstLine, lastLine = scriptDocument:GetViewport()
print(`現在の表示行は {firstLine} から {lastLine} です`)
else
print("スクリプトが開いていません")
endHasSelectedText
戻り値
コードサンプル
ScriptDocument:HasSelectedText() と :GetSelectedText()
--!nocheck
-- スクリプトが開いている間に、コマンドバーで以下のコードを実行してください
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectionChanged:Connect(function()
if scriptDocument:HasSelectedText() then
local selectedText = scriptDocument:GetSelectedText()
print(`現在選択されているテキスト: {selectedText}`)
else
print("現在選択されているテキストはありません")
end
end)
else
print("スクリプトは開いていません")
endIsCommandBar
戻り値
コードサンプル
ScriptDocument:IsCommandBar()
---!nocheck
-- コマンドバーで次のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("コマンドバーのドキュメント:", document)
end
endRequestSetSelectionAsync
戻り値
コードサンプル
スクリプトドキュメント:RequestSetSelectionAsync()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
-- カーソルの現在の行のテキストを取得
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- テキストの全行を強制的に選択
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("選択が設定されました!")
else
print(`選択の設定に失敗しました: {err}`)
end
else
print("スクリプトが開いていません")
endイベント
SelectionChanged
ScriptDocument.SelectionChanged(
コードサンプル
ScriptDocument.SelectionChanged と ScriptDocument:GetLine()
--!nocheck
-- スクリプトが開いている間にコマンドバーで以下のコードを実行します
local ScriptEditorService = game:GetService("ScriptEditorService")
local function getFirstOpenDocument()
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if not document:IsCommandBar() then
return document
end
end
return nil
end
local scriptDocument = getFirstOpenDocument()
if scriptDocument then
scriptDocument.SelectionChanged:Connect(function(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`選択された: 行 {positionLine}, 文字 {positionCharacter}`)
print(`アンカー: 行 {anchorLine}, 文字 {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`選択された行のテキスト: {lineText}`)
end)
else
print("スクリプトが開いていません")
endViewportChanged
コードサンプル
ScriptDocument.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)