ShotScript in a place
ShotScript scripts live in an ordinary Roblox place, next to plain Luau, and go into it as the Luau the place runs.
Most of a place's scripts stay plain Luau. The ones written in ShotScript keep their ShotScript text inside their own Source. ShotScript Editor checks that text as you type and writes it into the place by itself, compiled.
The mark
A ShotScript script is an ordinary script with its text inside it.
A ShotScript script is a ModuleScript, or a Script with RunContext Server or Client for a boot script. A client boot script may also be a LocalScript: one inserted in StarterPlayerScripts, StarterCharacterScripts, StarterGui or StarterPack is made a LocalScript. Its Source is its compiled Luau, followed by a comment that holds its ShotScript text. That text is the source of truth. The Luau above it is the compiled result, and every compile writes it again.
-- the compiled Luau, which Studio runs
--[=[ SHOT hash=<16 hex digits>
-- the ShotScript text, which you edit
]=]- Because the Source is plain Luau, Studio runs the place the same on a computer without ShotScript Editor.
- A script with no such comment is plain Luau. It is checked strict, as it is, and nothing is compiled for it.
It compiles as you go
Your typing goes into the place, compiled.
ShotScript Editor checks the text as you type and writes it into the script's Source by itself, as the Luau Studio runs. There is no step to keep your work.
A script that doesn't compile is refused. Only the comment takes your text, and the compiled Luau starts with an error stub ahead of the last good Luau, so Play stops loudly at that script. The editor says so in one line, with the row's fix when it has one:
Not compiled: <the row's reason> (line N). This script errors in Play until it compiles.- A row on a line you are still typing is a warning in the tab, and a refusal when it compiles.
- Problems lists ShotScript's own rules beside Studio's (see Docks).
- To compile a whole Folder or Model at once, use Compile Group in ShotScript Explorer (see Docks).
The guard
A hand edit of the Luau is never written over silently.
The comment's first line holds a hash of the compiled Luau above it: 16 hex digits of its SHA-256. When the Luau no longer matches the hash, someone edited it by hand, and the ShotScript text no longer makes what is there. The editor refuses Luau that was edited by hand, unless you choose to overwrite it.
- To keep a change, make it in the ShotScript text.
Types in the editor only
A switch per place keeps the types in the editor and out of the place's Luau.
The Types in Editor item of the Problems dock switches one place (see Docks). Once a place is switched, its compiled Luau keeps your text byte for byte, drops every type the compile added and starts --!nocheck, while ShotScript stays strict in the editor.
- Switching is one Studio step, and one Ctrl+Z takes it back.
- In a switched place, the
Types module the compile makes is empty. - No shot command switches a place.
Requires
ShotScript and plain Luau use each other.
A use line is local X = require(...), on its own line, with a Roblox path. These three could all sit in one script, Shop:
use script.Parent.Wallet.Ledger
use Wallet
use game.ReplicatedStorage.Shot.Format- A bare use X finds the nearest X: the script's own children, then its folder, then each folder up to the top. A script beats a folder.
- use script.Parent.X takes a path from the script, and use <path> as Name names the local.
- A path from game stays rooted at game in the compiled Luau, so a Tool cloned out of ServerStorage still finds what it named.
- use reaches plain Luau too, and requires it with its real types. A plain require(...) still works.
- A use whose path reaches nothing yet still compiles to its require and gives Luau's "Unknown require" warning, not an error. It stays an error when the name lives somewhere else, in a script or a remote of that name. When one place answers, the row's fix writes its game. path.
Adopting a plain module
Plain Luau is already ShotScript.
A plain module's Luau is already ShotScript, so it can become a ShotScript script with its own source as its ShotScript text.
- In ShotScript Explorer, Mark as ShotScript does it for the scripts you pick, in one undo step (see Docks).
- From a terminal, shot from-luau prints what Mark as ShotScript would write. It names one script of the open place by its place path or its name.
shot from-luau <script> [--json]- It exits with 0 when the text would compile, and 1 when it wouldn't or an option is bad.
- It exits with 2 when there is no argument, two names, a name that matches more than one script or no script at all, or when the place isn't open.
Hidden server code
Server code is never sent to players.
In a place, every script stays where it stands. Where it stands decides how its server code is kept from players.
- Under ServerStorage or ServerScriptService, a server item stays a plain ModuleScript, since no client reads those.
- A server item that clients could reach, in ReplicatedStorage, Workspace or another service every client gets, compiles hidden. It becomes a Script with RunContext Server that holds the code, which no client gets, and a small Public ModuleScript that stands in for it. Every require of it goes to that Public.
- A plain Luau script requires it through that Public too, and gets the item's own type. Requiring the item itself gets a row whose fix adds .Public.
- The editor does all of it as it compiles. There is nothing to write by hand.
- Only when it compiles a hidden server item (a Script plus its Public stub) does the editor place a ServerModule in the ShotSystem folder of ReplicatedStorage.Shot, making the Shot and ShotSystem folders as needed. Other compiles place nothing there.
- Two hidden items that use each other would wait on each other forever, so a use loop through a hidden item is an error.
- A Public that waits over 5 seconds warns.
The shot command
The shot command comes with ShotScript Editor.
ShotScript Editor carries ShotScript's shot command, and the install puts it on your Path, so shot works in any new terminal. It reads, checks and changes a place open in Studio (see The shot command).
