Classe de moteur
ScriptDocument
*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
MultiEditTextAsync(edits: {any}):Tuple |
ReviewableTextEditsAsync(changes: {any}):Tuple |
Événements
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal |
ViewportChanged(startLine: number,endLine: number):RBXScriptSignal |
Référence API
Méthodes
CloseAsync
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")
endEditTextAsync
ForceSetSelectionAsync
Retours
Échantillons de code
ScriptDocument:ForceSetSelectionAsync()
--!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 de la ligne actuelle du curseur
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Sélectionnez 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 définition de la sélection en raison de : {err}`)
end
else
print("Aucun script ouvert")
endGetLine
Paramètres
| Valeur par défaut : "nil" |
Retours
Échantillons de code
ScriptDocument.SelectionChanged et ScriptDocument:GetLine()
--!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(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Sélectionné : Ligne {positionLine}, Char {positionCharacter}`)
print(`Ancre : Ligne {anchorLine}, Char {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Texte de la ligne sélectionnée : {lineText}`)
end)
else
print("Aucun script ouvert")
endGetLineCount
Retours
Échantillons de code
ScriptDocument:GetLineCount()
--!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 lineCount = scriptDocument:GetLineCount()
print(`Le script a {lineCount} lignes !`)
else
print("Aucun script ouvert")
endGetScript
Retours
É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")
endGetSelectedText
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")
endGetSelectionEnd
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")
endGetSelectionStart
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")
endGetText
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")
endGetViewport
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")
endHasSelectedText
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")
endIsCommandBar
Retours
Échantillons de code
ScriptDocument:IsCommandBar()
--!nocheck
-- Exécutez le code suivant dans la barre de commande
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Document de la barre de commande:", document)
end
endMultiEditTextAsync
RequestSetSelectionAsync
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 de la ligne actuelle du curseur
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Sélectionnez 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 en raison de : {err}`)
end
else
print("Aucun script ouvert")
endÉvénements
SelectionChanged
ScriptDocument.SelectionChanged(
Échantillons de code
ScriptDocument.SelectionChanged et ScriptDocument:GetLine()
--!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(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Sélectionné : Ligne {positionLine}, Char {positionCharacter}`)
print(`Ancre : Ligne {anchorLine}, Char {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Texte de la ligne sélectionnée : {lineText}`)
end)
else
print("Aucun script ouvert")
endViewportChanged
Échantillons de code
Connexion à ScriptDocument.ViewportChanged
--!nocheck
--[[
Pour exécuter :
1. Assurez-vous que la vue de sortie est ouverte
2. Exécutez le code ci-dessous dans la barre de commande
3. Faites défiler vers le haut et vers le bas dans la fenêtre de script ouverte
Les instructions d'impression de l'événement ViewportChanged apparaîtront dans la sortie
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Créer un texte qui s'étend sur plusieurs lignes
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Créer un script contenant le texte fictif et l'ouvrir
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 en raison de : {err}`)
return
end
-- Obtenir une référence au script ouvert
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Changement de vue du script - startLine: {startLine}, endLine: {endLine}`)
end
-- Connecter l'événement ViewportChanged à la fonction ci-dessus qui imprime la ligne de début et la ligne de fin de la vue mise à jour
scriptDocument.ViewportChanged:Connect(onViewportChanged)