Command Line

The ShotScript Command Line runs a few lines of ShotScript in Studio, and its computer library reaches the files on your computer.

It is a dock like Studio's Command Bar: you write ShotScript in it, with your place's systems at hand.

Open it

One dock, at the bottom of Studio.

The Command button on Studio's Shot tab opens the ShotScript Command Line dock. It starts one line tall at the bottom of Studio, as the Command Bar does, and tabs, docks and floats like the other docks (see Docks).

Run a line

Type, then Ctrl+Enter.

  • Write one line or several: Enter starts a new line. The dock grows with your text up to ten lines, in ShotScript's colours.
  • A line longer than the dock scrolls sideways, with its scroll bar under the whole line, never over the letters. When you cut it back short, the bar goes and the line is one line tall again.
  • Pasting two lines grows the dock as typing them does, and the dock shows from line 1.
  • The dock has the completion list and underlines problems as you type, as a script tab does (see Script tabs).
  • Hover a name to see its type and docs. F12 on a name your text makes goes to it in the dock, and on a script's name opens that script. Find Usages (Shift+F12) lists where a name is used.
  • F2 renames a name your text makes. It never changes a script of the place: on any other name it says rename works only on names made in the command line.
  • Ctrl+Enter runs it, and your text stays in the dock. print and warn go to Studio's Output, as they do from any script.
  • Ctrl+Up and Ctrl+Down bring back your last 50 runs. Ctrl+Up brings a long one back with its scroll bar under it.
  • Below your text the dock shows how the run went: the scripts it loaded, then the time it took, or its error with the script and line the error came from.
  • A line with an error, such as a misspelt pirnt, shows its error. One Ctrl+Enter on it lists the error once, and nothing runs.
  • An overloaded call in a script the line loads runs the overload the editor picks for it (Classes, OVERLOADS). A call there the editor can't pick, such as "Update can't be picked", is listed the same way, and nothing runs.
  • A line runs on your scripts as their tabs show them, so a change you just typed is in it.
  • In edit, one Ctrl+Z takes back what the run changed in the place. Each asset it writes or makes is an undo step of its own (ASSETS).
  • One line runs at a time in each view. Ctrl+Enter starts nothing new while a run is going.

This line writes the names of Workspace's children to a file. Put a full path of your own, from the drive letter, in place of the words in angle brackets:

local names = {}
for _, child in workspace:GetChildren() do
    table.insert(names, child.Name)
end
computer.fileWrite("<a full path to a new file>", table.concat(names, "\n"))
print(#names, "names written")

Stop

Ends a run, and what it left running.

While a line runs, the dock shows Stop. Stop ends the line's own code, and a computer call made after that errors: "computer: this run was stopped".

A connection or a loop the line started keeps going after the line is done, as it would from the Command Bar, and keeps computer until you press Stop or 20 newer runs have finished. Stop stays in the dock for that: after the line is done, it ends computer for what the line left running.

When the line ends

Code that runs once the line is done.

__COMMAND is one object for each run: your line and every script the run loads see the same one. __COMMAND.BindToClose(fn) runs fn when the line returns, errors or is stopped.

local started = os.clock()
__COMMAND.BindToClose(function()
    print("took", os.clock() - started)
end)

A cleanup that calls computer pauses, so write its function async:

__COMMAND.BindToClose(async function()
    computer.flagRelease("Scores/count")
end)
  • Each function runs in its own thread, and the run waits up to 5 seconds for them in all. computer still works in them.
  • A plain function that never pauses fits too, as in the first sample.
  • Outside the command line a call to it errors: "__COMMAND is only in the command line".

What a line reaches

The place, and the scripts your text names.

  • In edit, a line runs in the place. While you play, it runs in the running game, on the side Studio is showing you: the server or the client.
  • use, start and require load the place's ModuleScripts, ShotScript or plain Luau, and whatever those load in turn. A line loads no other script, and never a Boot Script. An import brings types only and loads nothing.
  • Code may follow a use or start on the same line and runs after it, as in use Greet local w = 5 print(w). In a script a use stands alone on its line.
  • Each run loads its own new copy of every system it uses. While you play, a use gives a fresh copy, not the one the game is running: reach the running game through game.
  • A line has no script. Name a script from game, as in require(game.ReplicatedStorage.Kit).

Computer

Files, big files, assets, web requests, PNG images, sound, meshes, encryption and flags, for a command line run.

Only a run from the command line gets computer: your line, and the ShotScript scripts it loads. Anywhere else a call to it errors, except in Studio's Play of a place you trust (TRUSTED PLACES). Plain Luau modules never get it.

  • Each call waits for its answer, as an HttpService call does, so it can't be made inside a metamethod or a table.sort comparer.
  • A function that makes a call pauses, so it needs async (see Classes, ASYNC FUNCTIONS).
  • A call that fails errors at your line, with computer.<name>: <why>.
  • A position in a file or a string counts from 1, as in string.sub. A position in a buffer counts from 0, as in buffer.readu8.
  • A path is a full Windows path, from the drive letter, with either slash. Network paths, device paths and network drives are refused.
  • data is a buffer or a string. One call moves 256 MB at most.

Files

Whole files, read and written in one call.

computer.fileType(path)"File", "Folder" or "None"
computer.fileInfo(path){ Created, Modified }: a file's or a folder's times, in Unix seconds
computer.fileChildren(path)the names in a folder, sorted, hidden files too
computer.fileRead(path)the whole file, as a buffer
computer.fileReadString(path)the whole file, as a string
computer.fileWrite(path, data)the file becomes data, all at once; missing folders are made
computer.fileAppend(path, data)adds data at the end of the file; a missing file is made, with its folders
computer.fileRename(path, newPath)a file or a folder; it never replaces one that is there
computer.fileDelete(path)a file, or a folder and all it holds, deleted for good
computer.fileCreateFolder(path)the folder and any missing folders above it
  • fileInfo's times are whole seconds, as os.time() gives them, so DateTime.fromUnixTimestamp reads them. A missing path errors.
  • fileAppend opens the file, writes at its end and closes it, in one call. Unlike fileWrite it isn't all at once: a crash midway can leave part of the data written.
  • fileDelete never uses the Recycle Bin, and it never deletes a whole drive.
  • Read a file over 256 MB with a handle (BIG FILES).

Big files

A handle reads and writes part of a file.

computer.handleOpen(path)opens a file that exists and gives its handle
computer.handleSize(handle)the file's size now
computer.handleRead(handle, start, bytes)up to bytes from start, as a buffer
computer.handleReadString(handle, start, chars)the same, as a string
computer.handleAppend(handle, data)writes data at the end
computer.handleOverwrite(handle, data, start)writes data over the bytes from start, growing the file past its end
computer.handleOverwriteAll(handle, data)the file becomes data
computer.handleClose(handle)closes it
  • start is 1 for the first byte. A read gives 64 MB at most, fewer bytes at the end of the file, and none past it.
  • handleOverwrite and handleOverwriteAll write in place, so a crash midway leaves part of the data written. fileWrite is the all-at-once write.
  • 64 handles may be open at once in each view.

Assets

A file's bytes, kept in the place.

An asset is a ModuleScript that holds a file's bytes, so a picture, a sound or a mesh file goes wherever the place goes.

computer.assetCreate(data, name)a new asset holding data, named name (Asset when left out), with no parent
computer.assetFromFile(path)a new asset holding a file's bytes, named after the file
computer.assetRead(asset)its bytes, as a buffer
computer.assetReadString(asset)its bytes, as a string
computer.assetWrite(asset, data)its bytes become data
computer.assetSave(asset, path)writes its bytes to a file
  • An asset holds 64 MB at most.

Web requests

One request, one answer.

computer.fetch(url, method, headers, body) sends one request and gives back { Status, Headers, Body }:

local answer = computer.fetch("https://www.roblox.com", "GET", {})
print(answer.Status, buffer.len(answer.Body))
  • url is an http or https address. method is "GET", "POST", "PATCH" or "DELETE". headers is a table of names and values. body, a string or a buffer, may be left out.
  • Every status is an answer. fetch errors only when no answer comes: no connection, 30 seconds to connect, 300 to receive, or over 10 redirects.
  • Body is a buffer. Header names come in lower case.
  • It sends no cookie you didn't put in headers. A redirect to another host drops the Cookie and Authorization headers.

Images

Pixels into a PNG, and back out.

computer.pngEncode(size, pixels)the bytes of a PNG file holding the pixels
computer.pngDecode(png)the image's size, a Vector2, and its pixels
  • Pixels are a buffer of RGBA8, 4 bytes a pixel, rows top first: exactly X * Y * 4 bytes. size's X and Y are whole numbers from 1.
  • pngEncode errors when the pixels are the wrong length: "pixels hold 8,000 bytes; a 64 x 32 image needs 8,192: RGBA8, 4 bytes a pixel".
  • pngDecode reads any PNG: any bit depth, palette, grey or interlaced. The pixels come out as RGBA8 with straight alpha, and colour profiles are ignored. Bytes that aren't a PNG error.

Sound

Ogg Vorbis and WAV, either way.

computer.soundConvert(data, "OGG", "WAV")the Ogg Vorbis sound as WAV
computer.soundConvert(data, "WAV", "OGG")the WAV sound as Ogg Vorbis
  • The arguments are the data, its format and the format you want, each "OGG" or "WAV".
  • WAV in: PCM 8, 16, 24 or 32 bit, float 32 or 64, extensible, or RF64. WAV out: 16-bit PCM.
  • OGG is Ogg Vorbis only, both ways, written at quality 0.4. Other Ogg files, such as FLAC in Ogg, error: "only Ogg Vorbis".
  • The rate and channels are kept. With the same format twice, the data is checked and given back unchanged.

Meshes

Roblox's Draco meshes read, and mesh files converted.

computer.meshDecode(draco)the points and faces of a Draco mesh
computer.meshConvert(data, source, target)the mesh in the target format; source and target are "OBJ", "FBX" or "BLX"
  • meshDecode reads the bytes of a Roblox mesh's Draco chunk; your code finds the chunk in the mesh. It gives { Points, FaceCount, Faces, Attributes }. Faces holds three u32 point numbers per face, counting from 0. A point cloud has FaceCount 0.
  • Each attribute is { Kind, Components, Format, Data }. Kind is its place in the stream; in a Roblox mesh 0 is the position (f32 x 3), 1 the normal (f32 x 3), 2 the uv (f32 x 2), 3 the tangent (u8 x 4) and 4 the colour (u8 x 4). Format is "f32", "u8", "i8", "u16", "i16", "u32" or "i32". Data holds Points * Components values, little-endian, point 0 first.
  • meshConvert: FBX keeps everything, bones, weights and tangents included. OBJ loses bones, weights and tangents. From an OBJ, BLX gets zero tangents, and white colours and flat normals when the OBJ has none. FBX to BLX joins every mesh in world space, in triangles.
  • BLX is in Roblox's axes. FBX and OBJ share another: Roblox's (x, y, z) becomes (-x, y, -z), and v becomes 1 - v.
  • meshConvert errors on a bone name over 255 bytes, a BLX vertex count that isn't a multiple of 3, a BLX file cut short, and an FBX or OBJ it can't read. With the same source and target, the data is checked and given back unchanged.
  • Each PNG, sound or mesh call runs apart from the editor, so a bad file can't close it. That one call errors, "the converter stopped on this input", and the next call works.

Encryption

Bytes only you can open again.

computer.encrypt(data)bytes that only this Windows user on this computer can open
computer.decrypt(data)the bytes back
  • Both take a buffer and give a buffer. Windows does the encryption for your Windows account, so there is no key to keep.
  • decrypt errors on bytes made by another user or on another computer.

Flags

One holder at a time, across every Studio on the computer.

A flag is a name that one run holds at a time, so two runs don't do one job at once. Every Studio and place on the computer shares the same flags.

computer.flagPickup(name)true: it was free and is yours now; false: it is held. It never waits
computer.flagPickupAsync(name)waits until the flag is yours, first come, first served
computer.flagRelease(name)frees it, whoever holds it
computer.flagList()the names of the flags held now, sorted
  • A name is 1 to 200 bytes. Every Studio shares the names, so give yours a prefix, as in "Scores/count".
  • A flag stays held until something releases it, or until the view that picked it up closes. The command line's Stop frees none, and neither does a restart of ShotScript Editor.
  • Each flag remembers the view that picked it up: edit, the Play server or the Play client. When that view closes, by Play's Stop, the place or Studio closing, or Studio ended from Task Manager, the flag is freed and the next flagPickupAsync waiter gets it.
  • A flag picked up in edit stays until the place closes, so release it yourself, for example from an async __COMMAND.BindToClose function (WHEN THE LINE ENDS).
  • For a read, change and write that two runs may share: pick the flag up, do the work inside pcall, then release the flag on every path, error or not.
  • A run that waits for a flag it already holds waits until you press Stop.

Trusted places

computer in Studio's Play, for a place you trust.

Each published place's row in ShotScript Editor's window has Trust this game?, off at first (see Install). While it is on, the ShotScript scripts in that place's Studio Play can call computer, on the server and the client, as a command line run does.

  • ShotScript Editor keeps the setting for each game and place, so each place of a game has its own.
  • A solo Play gets it in both its views, the server and the client, and so does Run.
  • Live games and Team Test never get it, whatever the setting.
  • A place file never published to Roblox has no Trust this game?, so it never gets it. A call in its Play errors at once, with no wait: "computer works in Play only in a trusted published place: this place is a local file, so publish it to Roblox first, then Trust this game? in the ShotScript Editor's window".
  • A Boot Script may call computer too, with no row. Its calls work only in a trusted place's Play.
  • Without trust, a call in Play errors at once: "computer works in Play only when this place is trusted: Trust this game? in the ShotScript Editor's window".
  • In a trusted place's Play, a call in Play's first 10 seconds waits for ShotScript Editor to answer instead of erroring at once. If it never answers, the call errors: "the ShotScript Editor hasn't answered this Play yet".
  • A change to the setting counts from the next call.
  • Trust only a place whose scripts you know: while it is on, the scripts in its Play reach the files on your computer.