Engine-klasse
ScriptDocument
*Deze inhoud is vertaald met behulp van AI (bèta) en kan fouten bevatten. Klik hier om deze pagina in het Engels te bekijken.
Samenvatting
Methoden
AddReadOnlyReasonsAsync(reasons: {any}):() |
MultiEditTextAsync(edits: {any}):Tuple |
RemoveReadOnlyReasonsAsync(reasons: {any}):() |
ReviewableTextEditsAsync(changes: {any}):Tuple |
Evenementen
SelectionChanged(positionLine: number,positionCharacter: number,anchorLine: number,anchorCharacter: number):RBXScriptSignal |
ViewportChanged(startLine: number,endLine: number):RBXScriptSignal |
API-referentie
Methoden
AddReadOnlyReasonsAsync
Parameters
Teruggaves
()
Codevoorbeelden
ScriptDocument:AddReadOnlyReasonsAsync()
local ScriptEditorService = game:GetService("ScriptEditorService")
local Workspace = game:GetService("Workspace")
local newScript = Instance.new("Script")
newScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(newScript)
if not success then
warn(`Kon het scriptdocument niet openen: {err}`)
return
end
local scriptDocument = ScriptEditorService:FindScriptDocument(newScript)
-- Gebruik een redennaam die uniek is voor jouw plugin, zodat deze niet in conflict komt met andere plugins
scriptDocument:AddReadOnlyReasonsAsync({ "MyPluginReview" })
print(`{scriptDocument.Name} is alleen-lezen: {scriptDocument:IsReadOnly()}`)CloseAsync
Teruggaves
Codevoorbeelden
ScriptDocument:CloseAsync
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
local scriptDocument
-- Vind het eerste geopende scriptdocument
for _, document in documents do
-- De Opdrachtbalk kan niet worden gesloten, dus selecteer deze niet
if not document:IsCommandBar() then
scriptDocument = document
break
end
end
if scriptDocument then
local success, err = scriptDocument:CloseAsync()
if success then
print(`Gesloten {scriptDocument.Name}`)
else
warn(`Kon {scriptDocument.Name} niet sluiten omdat: {err}`)
end
else
print("Geen geopende scripts")
endEditTextAsync
ForceSetSelectionAsync
Teruggaves
Codevoorbeelden
ScriptDocument:ForceSetSelectionAsync()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
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
-- Verkrijg de tekst op de huidige regel van de cursor
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Dwing de hele regel tekst te selecteren
local success, err = scriptDocument:ForceSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Selectie ingesteld!")
else
print(`Selectie instellen mislukt omdat: {err}`)
end
else
print("Geen scripts open")
endGetLine
Parameters
| Standaardwaarde: nil |
Teruggaves
Codevoorbeelden
ScriptDocument.SelectieVeranderd en ScriptDocument:GetRegel()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
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.SelectieVeranderd:Connect(function(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Geselecteerd: Regel {positionLine}, Char {positionCharacter}`)
print(`Anker: Regel {anchorLine}, Char {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Geselecteerde regel tekst: {lineText}`)
end)
else
print("Geen scripts open")
endGetLineCount
Teruggaves
Codevoorbeelden
ScriptDocument:GetLineCount()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
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(`Het script heeft {lineCount} regels!`)
else
print("Geen scripts open")
endGetReadOnlyReasons
Teruggaves
{string}
Codevoorbeelden
ScriptDocument:GetReadOnlyReasons()
local ScriptEditorService = game:GetService("ScriptEditorService")
for _, document in ScriptEditorService:GetScriptDocuments() do
local reasons = document:GetReadOnlyReasons()
if #reasons > 0 then
print(`{document.Name} is alleen-lezen vanwege: {table.concat(reasons, ", ")}`)
end
endGetScript
Teruggaves
Codevoorbeelden
ScriptDocument:GetScript()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
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(`Huidig geopend script: {openScript:GetFullName()}`)
else
print("Geen scripts open")
endGetSelectedText
Teruggaves
Codevoorbeelden
ScriptDocument:HasSelectedText() en :GetSelectedText()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
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(`Huidig geselecteerde tekst: {selectedText}`)
else
print("Geen tekst momenteel geselecteerd")
end
end)
else
print("Geen scripts open")
endGetSelectionEnd
Teruggaves
Codevoorbeelden
ScriptDocument:GetSelectionStart() en :GetSelectionEnd()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
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(`Selectie start: Regel {startLine}, Char {startCharacter}`)
print(`Selectie eind: Regel {endLine}, Char {endCharacter}`)
else
print("Geen scripts open")
endGetSelectionStart
Teruggaves
Codevoorbeelden
ScriptDocument:GetSelectionStart() en :GetSelectionEnd()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
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(`Selectie start: Regel {startLine}, Char {startCharacter}`)
print(`Selectie eind: Regel {endLine}, Char {endCharacter}`)
else
print("Geen scripts open")
endGetText
Teruggaves
Codevoorbeelden
ScriptDocument:GetText()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
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(`Scriptinhoud: {text}`)
else
print("Geen scripts open")
endGetViewport
Teruggaves
Codevoorbeelden
ScriptDocument:GetViewport
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
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(`Momenteel bekijken lijnen {firstLine} tot {lastLine}`)
else
print("Geen scripts open")
endHasSelectedText
Teruggaves
Codevoorbeelden
ScriptDocument:HasSelectedText() en :GetSelectedText()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
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(`Huidig geselecteerde tekst: {selectedText}`)
else
print("Geen tekst momenteel geselecteerd")
end
end)
else
print("Geen scripts open")
endIsCommandBar
Teruggaves
Codevoorbeelden
ScriptDocument:IsCommandBar()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk
local ScriptEditorService = game:GetService("ScriptEditorService")
local documents = ScriptEditorService:GetScriptDocuments()
for _, document in documents do
if document:IsCommandBar() then
print("Opdrachtbalkdocument:", document)
end
endIsReadOnly
Teruggaves
Codevoorbeelden
ScriptDocument:IsReadOnly()
local ScriptEditorService = game:GetService("ScriptEditorService")
for _, document in ScriptEditorService:GetScriptDocuments() do
if document:IsReadOnly() then
print(`{document.Name} is alleen-lezen`)
else
print(`{document.Name} is bewerkbaar`)
end
endMultiEditTextAsync
RemoveReadOnlyReasonsAsync
Parameters
Teruggaves
()
Codevoorbeelden
ScriptDocument:RemoveReadOnlyReasonsAsync()
local ScriptEditorService = game:GetService("ScriptEditorService")
local Workspace = game:GetService("Workspace")
local newScript = Instance.new("Script")
newScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(newScript)
if not success then
warn(`Kon het scriptdocument niet openen: {err}`)
return
end
local scriptDocument = ScriptEditorService:FindScriptDocument(newScript)
scriptDocument:AddReadOnlyReasonsAsync({ "MyPluginReview", "MyPluginLocked" })
-- De editor blijft alleen-lezen terwijl er een andere reden actief blijft
scriptDocument:RemoveReadOnlyReasonsAsync({ "MyPluginReview" })
print(`Alleen-lezen na het verwijderen van één reden: {scriptDocument:IsReadOnly()}`)
scriptDocument:RemoveReadOnlyReasonsAsync({ "MyPluginLocked" })
print(`Alleen-lezen na het verwijderen van alle redenen: {scriptDocument:IsReadOnly()}`)RequestSetSelectionAsync
Teruggaves
Codevoorbeelden
ScriptDocument:RequestSetSelectionAsync()
--!nocheck
-- Voer de volgende code uit in de Command Bar terwijl een script open is
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
-- Verkrijg de tekst op de huidige regel van de cursor
local cursorLine = scriptDocument:GetSelection()
local lineText = scriptDocument:GetLine(cursorLine)
-- Dwing de hele regel tekst te selecteren
local success, err = scriptDocument:RequestSetSelectionAsync(cursorLine, 1, cursorLine, #lineText + 1)
if success then
print("Selectie ingesteld!")
else
print(`Selectie instellen mislukt omdat: {err}`)
end
else
print("Geen scripts open")
endEvenementen
SelectionChanged
ScriptDocument.SelectionChanged(
Codevoorbeelden
ScriptDocument.SelectieVeranderd en ScriptDocument:GetRegel()
--!nocheck
-- Voer de volgende code uit in de Opdrachtbalk terwijl een script open is
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.SelectieVeranderd:Connect(function(positionLine, positionCharacter, anchorLine, anchorCharacter)
print(`Geselecteerd: Regel {positionLine}, Char {positionCharacter}`)
print(`Anker: Regel {anchorLine}, Char {anchorCharacter}`)
local lineText = scriptDocument:GetLine(positionLine)
print(`Geselecteerde regel tekst: {lineText}`)
end)
else
print("Geen scripts open")
endViewportChanged
Codevoorbeelden
Verbinden met ScriptDocument.ViewportChanged
--!nocheck
--[[
Om te draaien:
1. Zorg ervoor dat de Output-weergave open is
2. Voer de onderstaande code in de Command Bar uit
3. Scroll omhoog en omlaag in het geopende Script-venster
Afdrukverklaringen van het ViewportChanged-evenement verschijnen in de Output
]]
local Workspace = game:GetService("Workspace")
local ScriptEditorService = game:GetService("ScriptEditorService")
-- Maak tekst die over meerdere regels gaat
local dummyText = string.rep("-- Dummy Text\n", 60)
-- Maak een script met de dummytekst en open het
local otherScript = Instance.new("Script")
otherScript.Source = dummyText
otherScript.Parent = Workspace
local success, err = ScriptEditorService:OpenScriptDocumentAsync(otherScript)
if not success then
warn(`Kon script niet openen omdat: {err}`)
return
end
-- Verkrijg een referentie naar het geopende script
local scriptDocument = ScriptEditorService:FindScriptDocument(otherScript)
local function onViewportChanged(startLine: number, endLine: number)
print(`Script Viewport Changed - startLine: {startLine}, endLine: {endLine}`)
end
-- Verbind het ViewportChanged-evenement met de bovenstaande functie die de start- en eindregel van de bijgewerkte viewport afdrukt
scriptDocument.ViewportChanged:Connect(onViewportChanged)