Skip to content

Built-in Functions

Prints a value to stdout with a newline.

Chant("Hello, world!");
Chant(42);
Chant([1, 2, 3]);

Prints a value to stdout without a trailing newline.

Whisper("Enter name: ");

Reads a line of input from stdin.

Whisper("What is your name? ");
Runestone name is Inscribe();
Chant("Hello, " + name + "!");

Reads the entire contents of a file as a string.

Runestone contents is ReadScroll("data.txt");
Chant(contents);

Writes a string to a file, overwriting any existing content.

WriteScroll("output.txt", "Hello from RuneLang!");

Appends a string to a file without overwriting.

AppendScroll("log.txt", "New entry\n");

Returns Truth if a file exists, Falsehood otherwise.

Quest begins when (ScrollExists("config.rune"))
Chant("Config found.");
elsewise
Chant("No config file.");
end of Quest

Returns the absolute value.

Chant(Abs(-42)); // 42
Chant(Abs(42)); // 42
Chant(Abs(-3.14)); // 3.14

Raises a number to a power. Equivalent to the ** operator.

Chant(Pow(2, 10)); // 1024

Returns the square root as a Potion (float).

Chant(Sqrt(144)); // 12
Chant(Sqrt(2)); // 1.4142135623730951

Returns the smaller or larger of two numbers.

Chant(Min(5, 3)); // 3
Chant(Max(5, 3)); // 5
Chant(Floor(3.7)); // 3
Chant(Ceil(3.2)); // 4
Chant(Round(3.5)); // 4
Chant(Round(3.4)); // 3
Chant(Sin(PI / 2)); // 1.0
Chant(Cos(0)); // 1.0
Chant(Tan(PI / 4)); // ~1.0

Natural logarithm (base e).

Chant(Log(EULER)); // 1.0
ConstantValueDescription
PI3.141592653589793Pi
TAU6.283185307179586Tau (2 * Pi)
EULER2.718281828459045Euler’s number (e)
INFINITYinfPositive infinity

Returns the length of a string, array, or map.

Chant(Measure("hello")); // 5
Chant(Measure([1, 2, 3])); // 3

Returns the type name as a string.

Chant(TypeOf(42)); // "Countstone"
Chant(TypeOf("hello")); // "Runestone"
Chant(TypeOf(3.14)); // "Potion"
Chant(TypeOf(Truth)); // "Flagstone"
Chant(TypeOf([1, 2])); // "Scroll"
Chant(TypeOf({})); // "Tome"

Converts a value to a different type.

Transmute(42, "Runestone") // "42"
Transmute("123", "Countstone") // 123
Transmute(3.14, "Countstone") // 3
Transmute(42, "Potion") // 42.0
Transmute(1, "Flagstone") // Truth

String formatting with {} placeholders.

Runestone msg is Format("{} has {} HP", "Thorin", 100);
Chant(msg); // "Thorin has 100 HP"

Creates an array of integers in a range.

Scroll r is Range(1, 6); // [1, 2, 3, 4, 5]
Scroll r2 is Range(0, 10); // [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Generates a random integer between min and max (inclusive). Useful for D&D-style dice rolls.

Countstone d20 is Roll(1, 20);
Chant("You rolled a " + d20 + "!");

Throws an error if the condition is Falsehood.

Assert(1 + 1 == 2); // passes
Assert(Falsehood); // ERROR: assertion failed

Immediately terminates the program.

Halt();

Returns the current Unix timestamp in milliseconds.

Potion now is Chronos();
Chant("Timestamp: " + now);

Pauses execution for the specified number of milliseconds.

Chant("Casting spell...");
Slumber(2000); // wait 2 seconds
Chant("Spell complete!");