Variables
Store, update, and reuse values with clear MiniScript+ variable names.
On this page
A variable gives a name to a value. Once assigned, that value can be read again or replaced later in the program.
Assign a value
Use = to assign the expression on the right to the name on the left.
score = 100playerName = "Alex"finished = FALSEAssignment does not print anything by itself. Use PRINT when you want to inspect a value.
score = 100PRINT scoreUpdate a variable
The right-hand side is evaluated first, then the result replaces the old value.
score = 10score = score + 5PRINT score # 15This pattern is especially useful for counters and totals.
Naming variables
Choose names that describe the value they contain.
| Prefer | Avoid | Reason |
|---|---|---|
studentCount | x | The purpose stays clear |
maximumScore | thing | The stored value is explicit |
isFinished | flag1 | Boolean intent is visible |
Variable names should begin with a letter or underscore and may contain digits after the first character.
Consistent style
camelCaseis used throughout these guides, but consistency matters more than a particular naming convention.
Expressions
Variables can participate in any expression just like literal values.
width = 8height = 5area = width * heightPRINT "Area:"PRINT areaCommon mistakes
- Reading a variable before assigning it.
- Using a quoted name when you meant the stored value.
- Reusing one vague name for unrelated values.
points = 25PRINT "points" # prints the text pointsPRINT points # prints 25Next, use variables to control loops.