**MiniScript** is a simple scripting language designed to be easily embedded in games and other software. It can also be used on the command line, or as a cross-platform game development environment via [Soda](https://github.com/JoeStrout/soda) or [Mini Micro](https://miniscript.org/MiniMicro).
An easy way to get started with MiniScript is on the [Try-It! page](https://miniscript.org/tryit/), which runs MiniScript code on the server. Note however that the code on this page is limited to 2000 characters. (The tutorial scripts below are broken up into blocks 2048 characters or less so they will run on the Try-It! page.)
Once you are ready to go beyond the Try-It! page, your next stop should probably be to download [Mini Micro](https://miniscript.org/MiniMicro), a free virtual computer that uses MiniScript both on the command line and in programs. In that environment, enter **edit** at the prompt to edit code, then click the Run button in the editor to run it.
```
print "Hello world"
// MiniScript is very syntax-light. Notice that no parentheses are
// needed on the print statement above. Comments begin with //, and
// extend to the end of the line. MiniScript is case-sensitive.
// CONTROL FLOW
// Use if blocks to do different things depending on some condition.
// Include zero or more else if blocks, and one optional else block.
if 2+2 == 4 then
print "math works!"
else if pi > 3 then
print "pi is tasty"
else if "a" < "b" then
print "I can sort"
else
print "last chance"
end if
// LOOPING
// MiniScript has only two loop constructs: while loops and for loops.
// Use a while block to loop as long as a condition is true.
s = "Spam"
while s.len <50
s = s + ", spam"
end while
print s + " and spam!"
// A for loop can loop over any list, including ones easily created
// with the range function.
for i in range(10, 1)
print i + "..."
end for
print "Liftoff!"
// Two additional keywords are useful inside loops. The break statement
// jumps out of the nearest while or for loop. The continue statement
// jumps to the top of the loop, skipping the rest of the current iteration.
for i in range(1,100)
if i % 3 == 0 then continue // skip multiples of 3
if i^2 > 200 then break // stop when i^2 is over 200
print i + " squared is " + i^2
end for
```
### Numbers
```
// All numbers are stored in full-precision format. Numbers also
// represent true (1) and false (0), and there are built-in keywords
// (true and false) for those.
a = 7
b = 3
ultimateAnswer = 42
pi = 3.14159
n = true
m = false
print ultimateAnswer + ", " + pi + ", " + n + ", " + m
// Numbers support the following operators:
print "Basic math:"
print a + b // addition
print a - b // subtraction
print a * b // multiplication
print a / b // division
print a % b // modulo (remainder)
print a ^ b // power
print "Logic:"
print n and m // logical "and"
print n or m // logical "or"
print not n // logical negation
print "Comparisons:"
print a == b // equality test (note == rather than = here!)
print a != b // inequality
print a > b // greater than
print a >= b // greater than or equal
print a <b//lessthan
print a <= b // less than or equal
```
### Strings
```
// Text is stored in strings of Unicode characters. Write strings
// by surrounding them with quotes. If you need to include a
// quotation mark in a string, type it twice.
print "Hello, ""Bob""."
a = "Hello"
b = "Spam"
// Strings support the following operators:
print "String ""math"":"
print a + b // string concatenation
print b - "m" // string subtraction (chop)
print b * 4 // string replication
print a / 2 // string division
print "Comparisons:"
print a == b // equality test (note == rather than = here!)
print a != b // inequality
print a > b // greater than
print a >= b // greater than or equal
print a <b//lessthan
print a <= b // less than or equal
// Indexing and slicing in a string is done with an index (or two)
// in square brackets. Use a 0-based index to count from the front,
// or a negative index to count from the end. Get a slice (substring)
// with two indices, separated by a colon. Either one may be omitted
// to extend the slice to the beginning or end of the string.
print "Indexing and slicing:"
print a[0] // get a character, starting with 0 ("H")
print a[1] // get second character ("e")
print a[-1] // negative numbers count from the end ("o")
print a[1:4] // get slice from 1 up to (but not including) 4 ("ell")
print a[1:-1] // same as above, but using a negative index
print a[1:] // get slice from 1 to the end ("ello")
print a[:2] // get slice from beginning up to 2 ("He")