Script Editor API: Now in Beta!

Does the new ScriptDocument.EditTextAsync function allow me to programmatically set the source of a script to have more than 200k characters?

My biggest problem with the existing API (and by that i just mean the Source property on Scripts) was that It would refuse to take a string longer than 200k. If I can now just repeatedly append to a script in smaller chunks that would completely solve my problem.

4 Likes

Been looking at the API change history and thought that this could be enabled on live experiences. Is there a reason to why we can’t enable this in our experiences?

3 Likes

Besides not having a Script Editor in live experiences, what would be a use case?

4 Likes

Well, I’m not sure how you would use a plugin in a live game

4 Likes

I hadn’t actually tried this, but it should!

For example,

local x = string.rep("-", 1000) .. "\n"; 
for i = 1, 500 do 
    game:GetService("ScriptEditorService"):FindScriptDocument(workspace.Script):EditTextAsync(x, i, 1, i, 1) 
    wait() 
end
10 Likes

To make a script made by the player run in the game. I have had this as a feature request for my Build Mode system.

2 Likes

Couldn’t you accomplish pretty much the same thing with loadstring?

1 Like

Yes! I needed this so much for my plugin. Now everything I need is an ability to highligh certain string patterns in the editor and open temporary script tabs.

Edit: Is this only for scripts which are opened in the script editor? :frowning:

2 Likes

They could already do that.

6 Likes

Yes, ScriptDocument represents a Studio Script Editor, so a Script that is not open in an editor will not have a ScriptDocument.

Suggestions welcome if this stops you from doing something!

4 Likes

Finally we can make plugins that can extend script editor functionality, can’t wait to see what talented creators will make. It’s gonna be a big upgrade for me since I use script editor 99% of my time spent in studio.

Also, is hot reloading a thing?

5 Likes

An epic idea, what if we could freely place and remove endpoints?? Better yet, an epic API feature for this class, the ability to pause and resume scripts!

3 Likes

Finally!

Will there be API to add things to the autocomplete menu? Or for things like displaying GUIs?

Imagine if you could have a ViewportFrame displayed when you hover over a variable holding a part, and that you could have the basic tools like resizing. Or if you could add custom functions shown in autocomplete, and when you press tab, it actually defines the function at the top of the script or at a place marked with a comment. Or if you could make it so changes other team members make would be shown above as a notification.

6 Likes

Dude that’s another solid feature suggestion. Imagine having a custom module that acts like a class, and being able to autocomplete using your own API… MIND BLOWN

4 Likes

THANK YOU! I’m working on a node-based visual scripter plugin and this will be just perfect to ease my development of it, thank you!

Every single person who contributed to this has earned my eternal respect.

3 Likes

Any chance we could get an API to close an open ScriptDocument?

You can already open scripts with plugin:OpenScript()

Could you walk me through your use-case for closing an editor from a plugin?

Not OP, but this could allow for adding functionality similar to VSCode’s Ctrl + K W shortcut, which closes all open script documents. It’d also allow for similar functionality such as mapping a keybind to close all scripts to the right of the open file.

1 Like

Rojo has a feature called “Open Scripts Externally” that will attempt to open a file in an external editor when you open the corresponding script in Studio. Since the file opens in your external editor Rojo closes the one in Studio. Here’s the relevant code:

https://github.com/rojo-rbx/rojo/blob/master/plugin/src/ServeSession.lua#L180

-- Force-close the script inside Studio... with a small delay in the middle
-- to prevent Studio from crashing.
spawn(function()
	local existingParent = activeScript.Parent
	activeScript.Parent = nil

	for i = 1, 3 do
		RunService.Heartbeat:Wait()
	end

	activeScript.Parent = existingParent
end)

As you can see this is pretty hacky and it interferes with other Rojo features because you are removing the script from the DataModel temporarily.

EDIT: I’m not sure if the delay is necessary. I just tested it and it doesn’t crash. However, it would still be nice to close a script without removing it.

8 Likes