Scripting tutorial #2: General Concepts and Syntax Rules
Remember the Goal
Understanding the intent behind a tool can help you get more out of it than you'd expect. The best programs out there are usually built around accomplishing a single, specific goal, and this determines everything from how they process data to how they interact with the user. Mike's Sprite Editor is, at heart, an image editor. Thus, the scripting language it uses is unique and entirely aimed at editing images.
This is not a common choice, as programs with scripting capabilities usually adopt an existing programming language like Scheme, Python, Lua, or Javascript rather than create their own from scratch. Now, these are all great languages, and the programs that use them are often excellent tools in their own right, but there's just one problem: these languages were created with specific purposes in mind, and those purposes may not translate directly into something the user needs. In fact, these languages are often used to create entire programs, so using them to supplement another program is often overkill.
Ultimately, scripting tools like those used in this editor are provided to make things easier - they're a shortcut, nothing more.
The Eight Syntax Rules
When we're talking about a language's "syntax", we're talking about the rules that govern how a language's sentences are formed. In English, this usually means we have a subject, object, and verb that are connected in a specific order. The sentence "Alice is going to the store" is easily understood, as it uses the Subject-Verb-Object pattern we normally see in English. We could say "To the store, Alice is going", but then we'd just sound like a Yoda impersonator.
Computers, for all their number crunching abilities, are actually really bad at understanding instructions that aren't written in just the right way. This is especially true for Mike's Sprite Editor, as it was designed to follow a very limited grammar.
In fact, the scripting language's grammar is so simple, it can be described with eight rules:
- Each instruction must be on its own line.
- Each instruction must start with a command.
- Blank lines and lines beginning with the REM command are ignored.
- Parameters follow the command, and are separated from it and each other by whitespace.
- In order to have a space or tab as part of a parameter, enclose that parameter with double quotes. Parameters like this are called Strings.
- Only Strings are case sensitive. This means out and OUT are the same command, while "This" and "this" are treated as completely different Strings.
- Because it's used to mark Strings, double quotes may not be used for anything else.
- Each script must have a marked start and end point. This is done using the commands START and END respectively.