Impara
Classe motore
ScriptDocument
Non costruibile
Non Replicato

*Questo contenuto è tradotto usando AI (Beta) e potrebbe contenere errori. Per visualizzare questa pagina in inglese, clicca qui.


Sommario
Metodi
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
Eventi
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
Membri ereditati

Riferimento API
Metodi
CloseAsync
Resa
Sicurezza Plugin
ScriptDocument:CloseAsync():Tuple
Restituzioni
Campioni di codice
ScriptDocument:CloseAsync
--!nocheck
-- Esegui il seguente codice nella Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Trova il primo documento di script aperto
for _, document in documents do
-- La Command Bar non può essere chiusa, quindi non selezionarla
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Chiuso {scriptDocument.Name}`)
else
warn(`Impossibile chiudere {scriptDocument.Name} perché: {err}`)
end
else
print("Nessuno script aperto")
end

EditTextAsync
Resa
Sicurezza Plugin
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
Parametri
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
Restituzioni

ForceSetSelectionAsync
Resa
Sicurezza Plugin
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parametri
cursorLine:number
cursorCharacter:number
anchorLine:number?
Valore predefinito: "nil"
anchorCharacter:number?
Valore predefinito: "nil"
Restituzioni
Campioni di codice
ScriptDocument:ForceSetSelectionAsync()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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
-- Ottieni il testo sulla riga corrente del cursore
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Forza la selezione dell'intera riga di testo
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Selezione impostata!")
else
print(`Impossibile impostare la selezione perché: {err}`)
end
else
print("Nessuno script aperto")
end

GetLine
Sicurezza Plugin
ScriptDocument:GetLine(lineIndex:number?):string
Parametri
lineIndex:number?
Valore predefinito: "nil"
Restituzioni
Campioni di codice
ScriptDocument.SelectionChanged e ScriptDocument:GetLine()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Selezionato: Linea {positionLine}, Carattere {positionCharacter}`)
print(`Ancora: Linea {anchorLine}, Carattere {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Testo della linea selezionata: {lineText}`)
end)
else
print("Nessuno script aperto")
end

GetLineCount
Sicurezza Plugin
ScriptDocument:GetLineCount():number
Restituzioni
Campioni di codice
ScriptDocument:GetLineCount()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Lo script ha {lineCount} righe!`)
else
print("Nessuno script aperto")
end

GetScript
Sicurezza Plugin
ScriptDocument:GetScript():LuaSourceContainer
Restituzioni
Campioni di codice
ScriptDocument:GetScript()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Script attualmente aperto: {openScript:GetFullName()}`)
else
print("Nessuno script aperto")
end

GetSelectedText
Sicurezza Plugin
ScriptDocument:GetSelectedText():string
Restituzioni
Campioni di codice
ScriptDocument:HasSelectedText() e :GetSelectedText()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Testo attualmente selezionato: {selectedText}`)
else
print("Nessun testo attualmente selezionato")
end
end)
else
print("Nessuno script aperto")
end

GetSelection
Sicurezza Plugin
ScriptDocument:GetSelection():Tuple
Restituzioni

GetSelectionEnd
Sicurezza Plugin
ScriptDocument:GetSelectionEnd():Tuple
Restituzioni
Campioni di codice
ScriptDocument:GetSelectionStart() e :GetSelectionEnd()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Inizio selezione: Riga {startLine}, Carattere {startCharacter}`)
print(`Fine selezione: Riga {endLine}, Carattere {endCharacter}`)
else
print("Nessuno script aperto")
end

GetSelectionStart
Sicurezza Plugin
ScriptDocument:GetSelectionStart():Tuple
Restituzioni
Campioni di codice
ScriptDocument:GetSelectionStart() e :GetSelectionEnd()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Inizio selezione: Riga {startLine}, Carattere {startCharacter}`)
print(`Fine selezione: Riga {endLine}, Carattere {endCharacter}`)
else
print("Nessuno script aperto")
end

GetText
Sicurezza Plugin
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
Parametri
startLine:number?
Valore predefinito: "nil"
startCharacter:number?
Valore predefinito: "nil"
endLine:number?
Valore predefinito: "nil"
endCharacter:number?
Valore predefinito: "nil"
Restituzioni
Campioni di codice
ScriptDocument:GetText()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Contenuti dello script: {text}`)
else
print("Nessuno script aperto")
end

GetViewport
Sicurezza Plugin
ScriptDocument:GetViewport():Tuple
Restituzioni
Campioni di codice
ScriptDocument:GetViewport
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Attualmente visualizzando le righe {firstLine} a {lastLine}`)
else
print("Nessuno script aperto")
end

HasSelectedText
Sicurezza Plugin
ScriptDocument:HasSelectedText():boolean
Restituzioni
Campioni di codice
ScriptDocument:HasSelectedText() e :GetSelectedText()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Testo attualmente selezionato: {selectedText}`)
else
print("Nessun testo attualmente selezionato")
end
end)
else
print("Nessuno script aperto")
end

IsCommandBar
Sicurezza Plugin
ScriptDocument:IsCommandBar():boolean
Restituzioni
Campioni di codice
ScriptDocument:IsCommandBar()
--!nocheck
-- Esegui il seguente codice nella Command Bar
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Documento della barra dei comandi:", document)
end
end

MultiEditTextAsync
Resa
Sicurezza Plugin
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
Parametri
edits:{any}
Restituzioni

RequestSetSelectionAsync
Resa
Sicurezza Plugin
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Parametri
cursorLine:number
cursorCharacter:number
anchorLine:number?
Valore predefinito: "nil"
anchorCharacter:number?
Valore predefinito: "nil"
Restituzioni
Campioni di codice
ScriptDocument:RequestSetSelectionAsync()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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
-- Ottieni il testo sulla riga corrente del cursore
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Forza la selezione dell'intera riga di testo
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Selezione impostata!")
else
print(`Impossibile impostare la selezione perché: {err}`)
end
else
print("Nessuno script aperto")
end

ReviewableTextEditsAsync
Resa
Sicurezza Plugin
ScriptDocument:ReviewableTextEditsAsync(changes:{any}):Tuple
Parametri
changes:{any}
Restituzioni

Eventi
SelectionChanged
Sicurezza Plugin
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
Parametri
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
Campioni di codice
ScriptDocument.SelectionChanged e ScriptDocument:GetLine()
--!nocheck
-- Esegui il seguente codice nella Command Bar mentre uno script è aperto
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(`Selezionato: Linea {positionLine}, Carattere {positionCharacter}`)
print(`Ancora: Linea {anchorLine}, Carattere {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Testo della linea selezionata: {lineText}`)
end)
else
print("Nessuno script aperto")
end

ViewportChanged
Sicurezza Plugin
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
Parametri
startLine:number
endLine:number
Campioni di codice
Collegamento a ScriptDocument.ViewportChanged
--!nocheck
--[[
Per eseguire:
1. Assicurati che la vista Output sia aperta
2. Esegui il codice qui sotto nella Command Bar
3. Scorri su e giù nella finestra dello Script aperta
Le istruzioni di stampa dall'evento ViewportChanged appariranno nell'Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Crea un testo che si estende su più righe
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Crea uno script contenente il testo fittizio e aprilo
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Impossibile aprire lo script perché: {err}`)
return
end
-- Ottieni un riferimento allo script aperto
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Viewport dello Script Cambiato - startLine: {startLine}, endLine: {endLine}`)
end
-- Collega l'evento ViewportChanged alla funzione sopra che stampa la linea di inizio e fine del viewport aggiornato
scriptDocument.ViewportChanged:Connect(onViewportChanged)

© 2026 Roblox Corporation. Roblox, il logo Roblox e Powering Imagination sono tra i nostri marchi registrati e non registrati negli Stati Uniti. e altri paesi.