In the examples that follow, the program appears in a dark box and the interpreter's trace appears in a light box beneath it. To follow along, put each program in a file and run skript run file.skript. Lines beginning with # are comments — the interpreter ignores them, humans should not:
# this is a comment log "this is not" # this part is a comment too
Script mode
The natural shape of a Skript program is a rule: "when something happens, do these steps." But while you are learning — or debugging — you can skip the rule and just write steps. A file of bare steps runs immediately, top to bottom, in what the trace calls script mode. It is the closest thing Skript has to a scratchpad, and we will use it heavily in the next few chapters.
log "Hello, Skode!"
▶ example.skript — Skode Skript · local simulation ● event: script → name: Demo • log → Hello, Skode! ✔ done in 2.1ms
The interpreter still shows an event line — script mode gives you a minimal stand-in event so the rest of the language behaves normally — followed by our one step. log writes a note into the trace. It is the print of Skode Skript: it does nothing to the outside world, but it is how a program shows you what it is thinking, and it is the tool this tutorial uses to make everything else visible.
Strings
A piece of text in quotes is a string. Double quotes and single quotes both work; use whichever avoids the quote you need inside:
log "A double-quoted string" log 'and a single-quoted one' log "escape a quote like \" this"
▶ example.skript — Skode Skript · local simulation ● event: script → name: Demo • log → A double-quoted string → assign to "and a single-quoted one" → event assigned • log → escape a quote like " this ✔ done in 2.1ms — assigned to and a single-quoted one
Strings are fully Unicode — accents, currency symbols and emoji are all just characters. (The printed edition of this book substitutes a few symbols that its fonts lack, but your terminal will show them faithfully.)
The most useful thing about Skript strings is interpolation: inside any string, a field name in curly braces is replaced by that field's value at the moment the string is used:
set city to "Kochi" log "Weather report for {city}"
▶ example.skript — Skode Skript · local simulation ● event: script → name: Demo ✎ set city → = "Kochi" • log → Weather report for Kochi ✔ done in 2.1ms
Interpolation reaches anything the program can see — fields of the incoming event, and variables you have created. If the name inside the braces is not set to anything, Skript leaves the braces in place rather than guessing, which makes typos easy to spot in a trace.
Numbers
Skript has ordinary numbers — whole and decimal — and ordinary arithmetic with +, -, * and /. Multiplication and division bind tighter than addition and subtraction, exactly as in school. One habit to learn immediately: put spaces around operators. budget * 2 is multiplication; budget*2 is just a strange name.
set subtotal to 40 + 2 set total to subtotal + 10 * 3 set half to total / 2 log "subtotal {subtotal}, total {total}, half {half}"
▶ example.skript — Skode Skript · local simulation ● event: script → name: Demo ✎ set subtotal → = 42 ✎ set total → = 72 ✎ set half → = 36 • log → subtotal 42, total 72, half 36 ✔ done in 2.1ms
Dividing by zero is an error, and Skript tells you so in words rather than in symbols. Arithmetic on something that is not a number — say, a name — is also an error; Chapter 13 shows what those look like.
+ pulls double duty: between two numbers it adds; if either side is a string, it joins:
set name to "Ada" set greeting to "Hello, " + name + "!" log "{greeting}"
▶ example.skript — Skode Skript · local simulation ● event: script → name: Demo ✎ set name → = "Ada" ✎ set greeting → = "Hello, Ada!" • log → Hello, Ada! ✔ done in 2.1ms
First steps towards programming
Of course, we can use Skript for more than adding numbers to greetings. Here is the beginning of something real — a little program that works out a discount. It introduces two ideas the next chapters will treat properly: variables that change, and a decision:
set price to 900 set discount to 0 if price is above 500 then set discount to price / 10 set final to price - discount log "price {price}, discount {discount}, final {final}"
▶ example.skript — Skode Skript · local simulation ● event: script → name: Demo ✎ set price → = 900 ✎ set discount → = 0 ✓ if price above 500 → yes ✎ set discount → = 90 ✎ set final → = 810 • log → price 900, discount 90, final 810 ✔ done in 2.1ms
Notice the shape of the if: the condition reads like a sentence (price is above 500), the word then is allowed but optional, and the step that belongs to the if is indented underneath it. Indentation is not decoration in Skript — it is how the language knows what belongs to what. There are no braces and no end keywords; the structure of the program is its visual structure. The interpreter treats two spaces as one level, and honestly, so should you.
This is everything you need to read the rest of the book: steps run top to bottom, quotes make strings, braces interpolate, spaces-around-operators make arithmetic, and indentation makes structure. Now let us meet the thing that makes Skript a Skode language rather than a calculator: events.