Line continuation

From MiniScript Wiki
Revision as of 14:40, 1 April 2024 by JoeStrout (talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

MiniScript statements are separated by line breaks rather than explicit punctuation (such as the semicolon in C). It is nonetheless possible to break a long MiniScript statement into multiple lines, by placing the line break immediately after any of:

  • an opening (, [, or {
  • a comma or colon: , or :
  • any binary operator: +, -, and, or, etc.

Examples

x = {
     "foo": "A commonly used variable name in example code",
     "bar":
        "A second commonly used example variable name" }

Note that the final } in this example is placed on the same line as the last enty. As an alternative, when writing a multi-line list or map, you can put the closing ] or } on its own line by appending a , to the last item, as in the following example.

states = [
   "Init",
   "Loading",
   "Running",
   "GameOver",
]

This has the added benefit that if you add or reorder your items, you don't have to fix up the commas — every item is followed by a comma, so they are all the same in that regard.