Informacje o wersji
Edukacja
Klasa silnika
ScriptDocument
Brak możliwości tworzenia
Bez replikacji

*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.


Podsumowanie
Metody
EditTextAsync(newText: string,startLine: number,startCharacter: number,endLine: number,endCharacter: number):Tuple
ForceSetSelectionAsync(cursorLine: number,cursorCharacter: number,anchorLine: number?,anchorCharacter: number?):Tuple
GetLine(lineIndex: number?):string
GetText(startLine: number?,startCharacter: number?,endLine: number?,endCharacter: number?):string
RequestSetSelectionAsync(cursorLine: number,cursorCharacter: number,anchorLine: number?,anchorCharacter: number?):Tuple
Zdarzenia
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
Członkowie odziedziczeni

Materiały referencyjne dotyczące interfejsów API
Metody
CloseAsync
Wynik
Zabezpieczenia dodatku plug-in
ScriptDocument:CloseAsync():Tuple
Zwroty
Przykłady kodu
DokumentSkryptu:ZamknijAsync
--!nocheck
-- Uruchom poniższy kod w pasku poleceń
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Znajdź pierwszy otwarty dokument skryptu
for _, document in documents do
-- Pasek poleceń nie może być zamknięty, więc nie wybieraj go
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Zamknięto {scriptDocument.Name}`)
else
warn(`Nie udało się zamknąć {scriptDocument.Name} ponieważ: {err}`)
end
else
print("Brak otwartych skryptów")
end

EditTextAsync
Wynik
Zabezpieczenia dodatku plug-in
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
Parametry
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
Zwroty

ForceSetSelectionAsync
Wynik
Zabezpieczenia dodatku plug-in
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parametry
cursorLine:number
cursorCharacter:number
anchorLine:number?
Wartość domyślna: "nil"
anchorCharacter:number?
Wartość domyślna: "nil"
Zwroty
Przykłady kodu
ScriptDocument:ForceSetSelectionAsync()
--!nocheck
-- Run the following code in the Command Bar while a script is open
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
-- Get the text on the cursor's current line
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Force select the entire line of text
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Set selection!")
else
print(`Failed to set selection because: {err}`)
end
else
print("No scripts open")
end

GetLine
Zabezpieczenia dodatku plug-in
ScriptDocument:GetLine(lineIndex:number?):string
Parametry
lineIndex:number?
Wartość domyślna: "nil"
Zwroty
Przykłady kodu
ScriptDocument.SelectionChanged i ScriptDocument:GetLine()
--!nocheck
-- Uruchom następujący kod w pasku polecenia, gdy skrypt jest otwarty
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(`Wybrano: Linia {positionLine}, Znak {positionCharacter}`)
print(`Kotwica: Linia {anchorLine}, Znak {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Wybrany tekst linii: {lineText}`)
end)
else
print("Brak otwartych skryptów")
end

GetLineCount
Zabezpieczenia dodatku plug-in
ScriptDocument:GetLineCount():number
Zwroty
Przykłady kodu
ScriptDocument:GetLineCount()
--!nocheck
-- Uruchom następujący kod w Command Bar, gdy skrypt jest otwarty
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(`Skrypt ma {lineCount} linii!`)
else
print("Brak otwartych skryptów")
end

GetScript
Zabezpieczenia dodatku plug-in
ScriptDocument:GetScript():LuaSourceContainer
Przykłady kodu
ScriptDocument:GetScript()
--!nocheck
-- Run the following code in the Command Bar while a script is open
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(`Currently open script: {openScript:GetFullName()}`)
else
print("No scripts open")
end

GetSelectedText
Zabezpieczenia dodatku plug-in
ScriptDocument:GetSelectedText():string
Zwroty
Przykłady kodu
ScriptDocument:HasSelectedText() i :GetSelectedText()
--!nocheck
-- Uruchom poniższy kod w Command Bar, gdy skrypt jest otwarty
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(`Obecnie wybrany tekst: {selectedText}`)
else
print("Nie ma obecnie wybranego tekstu")
end
end)
else
print("Nie ma otwartych skryptów")
end

GetSelection
Zabezpieczenia dodatku plug-in
ScriptDocument:GetSelection():Tuple
Zwroty

GetSelectionEnd
Zabezpieczenia dodatku plug-in
ScriptDocument:GetSelectionEnd():Tuple
Zwroty
Przykłady kodu
ScriptDocument:GetSelectionStart() oraz :GetSelectionEnd()
--!nocheck
-- Uruchom poniższy kod w pasku poleceń, gdy skrypt jest otwarty
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(`Początek wyboru: Linia {startLine}, Znak {startCharacter}`)
print(`Koniec wyboru: Linia {endLine}, Znak {endCharacter}`)
else
print("Nie ma otwartych skryptów")
end

GetSelectionStart
Zabezpieczenia dodatku plug-in
ScriptDocument:GetSelectionStart():Tuple
Zwroty
Przykłady kodu
ScriptDocument:GetSelectionStart() oraz :GetSelectionEnd()
--!nocheck
-- Uruchom poniższy kod w pasku poleceń, gdy skrypt jest otwarty
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(`Początek wyboru: Linia {startLine}, Znak {startCharacter}`)
print(`Koniec wyboru: Linia {endLine}, Znak {endCharacter}`)
else
print("Nie ma otwartych skryptów")
end

GetText
Zabezpieczenia dodatku plug-in
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
Parametry
startLine:number?
Wartość domyślna: "nil"
startCharacter:number?
Wartość domyślna: "nil"
endLine:number?
Wartość domyślna: "nil"
endCharacter:number?
Wartość domyślna: "nil"
Zwroty
Przykłady kodu
ScriptDocument:GetText()
--!nocheck
-- Run the following code in the Command Bar while a script is open
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(`Script contents: {text}`)
else
print("No scripts open")
end

GetViewport
Zabezpieczenia dodatku plug-in
ScriptDocument:GetViewport():Tuple
Zwroty
Przykłady kodu
ScriptDocument:GetViewport
--!nocheck
-- Uruchom poniższy kod w pasku poleceń, gdy skrypt jest otwarty
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(`Aktualnie wyświetlane linie {firstLine} do {lastLine}`)
else
print("Brak otwartych skryptów")
end

HasSelectedText
Zabezpieczenia dodatku plug-in
ScriptDocument:HasSelectedText():boolean
Zwroty
Przykłady kodu
ScriptDocument:HasSelectedText() i :GetSelectedText()
--!nocheck
-- Uruchom poniższy kod w Command Bar, gdy skrypt jest otwarty
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(`Obecnie wybrany tekst: {selectedText}`)
else
print("Nie ma obecnie wybranego tekstu")
end
end)
else
print("Nie ma otwartych skryptów")
end

IsCommandBar
Zabezpieczenia dodatku plug-in
ScriptDocument:IsCommandBar():boolean
Zwroty
Przykłady kodu
ScriptDocument:IsCommandBar()
--!nocheck
-- Uruchom następujący kod w Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Dokument Command Bar:", document)
end
end

MultiEditTextAsync
Wynik
Zabezpieczenia dodatku plug-in
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
Parametry
edits:{any}
Zwroty

RequestSetSelectionAsync
Wynik
Zabezpieczenia dodatku plug-in
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parametry
cursorLine:number
cursorCharacter:number
anchorLine:number?
Wartość domyślna: "nil"
anchorCharacter:number?
Wartość domyślna: "nil"
Zwroty
Przykłady kodu
ScriptDocument:RequestSetSelectionAsync()
--!nocheck
-- Uruchom poniższy kod w Oknie Komend, gdy skrypt jest otwarty
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
-- Pobierz tekst z bieżącej linii kursora
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Wymuś zaznaczenie całej linii tekstu
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Zaznaczono wybór!")
else
print(`Nie udało się ustawić zaznaczenia, ponieważ: {err}`)
end
else
print("Brak otwartych skryptów")
end

Zdarzenia
SelectionChanged
Zabezpieczenia dodatku plug-in
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
Parametry
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
Przykłady kodu
ScriptDocument.SelectionChanged i ScriptDocument:GetLine()
--!nocheck
-- Uruchom następujący kod w pasku polecenia, gdy skrypt jest otwarty
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(`Wybrano: Linia {positionLine}, Znak {positionCharacter}`)
print(`Kotwica: Linia {anchorLine}, Znak {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Wybrany tekst linii: {lineText}`)
end)
else
print("Brak otwartych skryptów")
end

ViewportChanged
Zabezpieczenia dodatku plug-in
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
Parametry
startLine:number
endLine:number
Przykłady kodu
Łączenie z ScriptDocument.ViewportChanged
--!nocheck
--[[
Aby uruchomić:
1. Upewnij się, że widok Output jest otwarty
2. Uruchom poniższy kod w Command Bar
3. Przewiń w górę i w dół w otwartym oknie Skryptu
Wydruki z zdarzenia ViewportChanged pojawią się w Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Utwórz tekst zajmujący wiele linii
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Utwórz skrypt zawierający tekst dummy i otwórz go
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Nie udało się otworzyć skryptu z powodu: {err}`)
return
end
-- Uzyskaj odniesienie do otwartego skryptu
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Widok skryptu zmieniony - startLine: {startLine}, endLine: {endLine}`)
end
-- Połącz zdarzenie ViewportChanged z powyższą funkcją, która drukuje pierwszą i ostatnią linię zaktualizowanego widoku
scriptDocument.ViewportChanged:Connect(onViewportChanged)

©2026 Roblox Corporation. Nazwa Roblox, logo Roblox oraz hasło „Powering Imagination” należą do naszych zarejestrowanych i niezarejestrowanych znaków towarowych na terenie Stanów Zjednoczonych oraz w innych krajach.