Apprendre
Classe de moteur
ScriptDocument
Création impossible
Non répliqué

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.


Résumé
Méthodes
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
Événements
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal
Membres hérités

Référence API
Méthodes
CloseAsync
Rendement
Sécurité des plugins
ScriptDocument:CloseAsync():Tuple
Retours
Échantillons de code
ScriptDocument:CloseAsync
--!nocheck
-- Exécutez le code suivant dans la barre de commandes
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Trouvez le premier document de script ouvert
for _, document in documents do
-- La barre de commandes ne peut pas être fermée, donc ne la sélectionnez pas
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Fermé {scriptDocument.Name}`)
else
warn(`Échec de la fermeture de {scriptDocument.Name} parce que : {err}`)
end
else
print("Aucun script ouvert")
end

EditTextAsync
Rendement
Sécurité des plugins
ScriptDocument:EditTextAsync(
newText:string, startLine:number, startCharacter:number, endLine:number, endCharacter:number
Paramètres
newText:string
startLine:number
startCharacter:number
endLine:number
endCharacter:number
Retours

ForceSetSelectionAsync
Rendement
Sécurité des plugins
ScriptDocument:ForceSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Paramètres
cursorLine:number
cursorCharacter:number
anchorLine:number?
Valeur par défaut : "nil"
anchorCharacter:number?
Valeur par défaut : "nil"
Retours
Échantillons de code
ScriptDocument:ForceSetSelectionAsync()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes alors qu'un script est ouvert
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
-- Obtenez le texte de la ligne actuelle du curseur
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Forcer la sélection de toute la ligne de texte
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Sélection définie!")
else
print(`Échec de la sélection parce que : {err}`)
end
else
print("Aucun script ouvert")
end

GetLine
Sécurité des plugins
ScriptDocument:GetLine(lineIndex:number?):string
Paramètres
lineIndex:number?
Valeur par défaut : "nil"
Retours
Échantillons de code
ScriptDocument.SelectionChanged et ScriptDocument:GetLine()
--!nocheck
-- Exécutez le code suivant dans la barre de commande pendant qu'un script est ouvert
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(`Sélectionné : Ligne {positionLine}, Caractère {positionCharacter}`)
print(`Ancre : Ligne {anchorLine}, Caractère {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Texte de la ligne sélectionnée : {lineText}`)
end)
else
print("Aucun script n'est ouvert")
end

GetLineCount
Sécurité des plugins
ScriptDocument:GetLineCount():number
Retours
Échantillons de code
ScriptDocument:GetLineCount()
--!nocheck
-- Exécutez le code suivant dans la barre de commande pendant qu'un script est ouvert
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(`Le script a {lineCount} lignes !`)
else
print("Aucun script ouvert")
end

GetScript
Sécurité des plugins
ScriptDocument:GetScript():LuaSourceContainer
Échantillons de code
ScriptDocument:GetScript()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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 actuellement ouvert : {openScript:GetFullName()}`)
else
print("Aucun script ouvert")
end

GetSelectedText
Sécurité des plugins
ScriptDocument:GetSelectedText():string
Retours
Échantillons de code
ScriptDocument:HasSelectedText() et :GetSelectedText()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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(`Texte actuellement sélectionné : {selectedText}`)
else
print("Aucun texte actuellement sélectionné")
end
end)
else
print("Aucun script ouvert")
end

GetSelection
Sécurité des plugins
ScriptDocument:GetSelection():Tuple
Retours

GetSelectionEnd
Sécurité des plugins
ScriptDocument:GetSelectionEnd():Tuple
Retours
Échantillons de code
ScriptDocument:GetSelectionStart() et :GetSelectionEnd()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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(`Début de la sélection : Ligne {startLine}, Char {startCharacter}`)
print(`Fin de la sélection : Ligne {endLine}, Char {endCharacter}`)
else
print("Aucun script ouvert")
end

GetSelectionStart
Sécurité des plugins
ScriptDocument:GetSelectionStart():Tuple
Retours
Échantillons de code
ScriptDocument:GetSelectionStart() et :GetSelectionEnd()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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(`Début de la sélection : Ligne {startLine}, Char {startCharacter}`)
print(`Fin de la sélection : Ligne {endLine}, Char {endCharacter}`)
else
print("Aucun script ouvert")
end

GetText
Sécurité des plugins
ScriptDocument:GetText(
startLine:number?, startCharacter:number?, endLine:number?, endCharacter:number?
Paramètres
startLine:number?
Valeur par défaut : "nil"
startCharacter:number?
Valeur par défaut : "nil"
endLine:number?
Valeur par défaut : "nil"
endCharacter:number?
Valeur par défaut : "nil"
Retours
Échantillons de code
ScriptDocument:GetText()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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(`Contenu du script : {text}`)
else
print("Aucun script ouvert")
end

GetViewport
Sécurité des plugins
ScriptDocument:GetViewport():Tuple
Retours
Échantillons de code
ScriptDocument:GetViewport
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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(`Actuellement en train de visualiser les lignes {firstLine} à {lastLine}`)
else
print("Aucun script ouvert")
end

HasSelectedText
Sécurité des plugins
ScriptDocument:HasSelectedText():boolean
Retours
Échantillons de code
ScriptDocument:HasSelectedText() et :GetSelectedText()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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(`Texte actuellement sélectionné : {selectedText}`)
else
print("Aucun texte actuellement sélectionné")
end
end)
else
print("Aucun script ouvert")
end

IsCommandBar
Sécurité des plugins
ScriptDocument:IsCommandBar():boolean
Retours
Échantillons de code
ScriptDocument:IsCommandBar()
--!nocheck
-- Exécutez le code suivant dans la barre de commandes
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Document de barre de commandes :", document)
end
end

MultiEditTextAsync
Rendement
Sécurité des plugins
ScriptDocument:MultiEditTextAsync(edits:{any}):Tuple
Paramètres
edits:{any}
Retours

RequestSetSelectionAsync
Rendement
Sécurité des plugins
ScriptDocument:RequestSetSelectionAsync(
cursorLine:number, cursorCharacter:number, anchorLine:number?, anchorCharacter:number?
Paramètres
cursorLine:number
cursorCharacter:number
anchorLine:number?
Valeur par défaut : "nil"
anchorCharacter:number?
Valeur par défaut : "nil"
Retours
Échantillons de code
ScriptDocument:RequestSetSelectionAsync()
---!nocheck
-- Exécutez le code suivant dans la barre de commandes pendant qu'un script est ouvert
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
-- Obtenez le texte sur la ligne actuelle du curseur
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Forcez la sélection de toute la ligne de texte
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Sélection définie !")
else
print(`Échec de la définition de la sélection car : {err}`)
end
else
print("Aucun script ouvert")
end

Événements
SelectionChanged
Sécurité des plugins
ScriptDocument.SelectionChanged(
positionLine:number, positionCharacter:number, anchorLine:number, anchorCharacter:number
Paramètres
positionLine:number
positionCharacter:number
anchorLine:number
anchorCharacter:number
Échantillons de code
ScriptDocument.SelectionChanged et ScriptDocument:GetLine()
--!nocheck
-- Exécutez le code suivant dans la barre de commande pendant qu'un script est ouvert
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(`Sélectionné : Ligne {positionLine}, Caractère {positionCharacter}`)
print(`Ancre : Ligne {anchorLine}, Caractère {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Texte de la ligne sélectionnée : {lineText}`)
end)
else
print("Aucun script n'est ouvert")
end

ViewportChanged
Sécurité des plugins
ScriptDocument.ViewportChanged(
startLine:number, endLine:number
Paramètres
startLine:number
endLine:number
Échantillons de code
Connexion à ScriptDocument.ViewportChanged
--!nocheck
--[[
Pour exécuter :
1. Assurez-vous que la vue Output est ouverte
2. Exécutez le code ci-dessous dans la barre de commandes
3. Faites défiler vers le haut et vers le bas dans la fenêtre du script ouverte
Les instructions Print de l'événement ViewportChanged apparaîtront dans la sortie
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Créez un texte qui s'étend sur plusieurs lignes
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Créez un script contenant le texte factice et ouvrez-le
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Échec de l'ouverture du script car : {err}`)
return
end
-- Obtenez une référence au script ouvert
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Zone d'affichage du script changée - ligne de départ : {startLine}, ligne de fin : {endLine}`)
end
-- Connectez l'événement ViewportChanged à la fonction ci-dessus qui imprime la ligne de départ et la ligne de fin de la zone d'affichage mise à jour
scriptDocument.ViewportChanged:Connect(onViewportChanged)

©2026 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.