The tour, 2 of 11
Values and types
Local, Const, and Global; the built-in types; strings and their interpolation.
A variable is declared before it’s used, with Local inside code, Global for a whole file’s,
and Const for a value that never changes. Its type comes from its value, or is written after a
colon.
Import std.core
Const MAX_HP = 100
Global score = 0
Local name = "grunt" // a String
Local hp: Int = 80
Local speed = 2.5 // a Float, 32 bits
Local alive = hp > 0 // a Bool
score += 10
Print("{name}: {hp}/{MAX_HP} hp, speed {speed}, alive {alive}, score {score}")grunt: 80/100 hp, speed 2.5, alive True, score 10
There are no type suffixes: name$ is name: String, and a variable that wasn’t declared is an
error, so a typo can’t make a new one.
The built-in types
| Type | What |
|---|---|
Int, Long | 32- and 64-bit integers, as are Int8 to Int64 and UInt8 to UInt64 |
Float, Double | 32- and 64-bit floating point |
Bool | True or False |
String | text, UTF-8, which never changes once made |
Char | one character, written 'A' |
Only conversions that lose nothing happen by themselves, like an Int to a Long or a
Double. The rest are written with As:
Import std.core
Local hp = 75
Local ratio = hp As Float / 100
Local rounded = 2.75 As Int // drops the fraction
Local wrapped = 300 As UInt8 // keeps the low 8 bits
Print(ratio, rounded, wrapped)
Print(True As Int, 'A' As Int)0.75 2 44 1 65
Strings
A string takes any value inside braces, and a format after a colon in them, as Python’s and
Rust’s do. + joins two strings.
Import std.core
Local player = "Ada"
Local gold = 1234
Local hit = 0.4567
Print("{player} has {gold:,} gold")
Print("hit chance {hit:.1%}")
Print("[{player:<8}] [{gold:>8}]")
Print("braces are doubled: {{like this}}")
Print("one " + "two")Ada has 1,234 gold
hit chance 45.7%
[Ada ] [ 1234]
braces are doubled: {like this}
one twoInteger overflow panics in a debug build, with the line where it happened, and wraps in a release build. Next: control flow.
Report an issue with this page or with FutureBlitz on GitHub.