Enter adds the end a block needs
ShotScript

Enter adds the end a block needs

By ShotScript Team2 min

Press Enter at the end of a line that opens a block, like a function or a for, in a ShotScript tab in ShotScript Editor, and the caret goes to a new line one step in. When the block has no end yet, its end comes too, on the line under the caret. A block that already has its end doesn't get a second one, and a case in a match gets none.

The script

In a new Baseplate we made ShotScript out of a plain Script called Menu in ServerScriptService, with ShotScript Explorer's right-click Mark as ShotScript. Its text stayed as it was.

ServerScriptService/Menu.shot
type Course = "Soup" | "Tart"

local courses: { Course } = { "Soup", "Tart" }

local function listCourses()
end

listCourses()

Every key below was pressed one at a time, and we never typed an end ourselves.

An empty block keeps its one end

We clicked at the end of local function listCourses(), whose end is on the next line, and pressed End and Enter. The caret went to a new line one step in, and the function kept its one end, now on line 7. A fold arrow appeared beside line 5.

The Menu tab in ShotScript Editor. The caret is on an empty line 6 inside listCourses, one step in, the function's end is on line 7, and no second end follows it.

A new block gets its end

On that line we typed for _, course in courses do and pressed Enter. The for got an end of its own, lined up with the for, and the caret sat on the new line between them, one more step in. The function still had one end.

Line 6 is for _, course in courses do, the caret is on line 7 two steps in, line 8 is the end added for the for, and line 9 is the function's end.

A case in a match has no end

On the new line we typed match course. A list of names opened as we typed, and Esc closed it. Enter gave the match its own end too, with the caret one step in.

There we typed "Tart" then and pressed Enter again. A case runs to the next case or to the match's end, so it needs no end of its own, and Enter added just the one line, with the caret one step in from the case.

Lines 7 and 8 are match course, with a blue wavy line under match, and the Tart case, and the caret is on line 9 one step in from the case. Line 10 is the match's end, line 11 the end of the for and line 12 the function's.

That left one end for each block, the match, the for and the function. The blue wavy line under match on line 7 is about the match itself: a Course can also be "Soup", and the match has no case for it yet. Holding the mouse over it shows this:

Warning
ShotScript Warning: match on Course has no case for "Soup": add the case, or an else

It has nothing to do with Enter.