Built-in Functions
Prints a value to stdout with a newline.
Chant("Hello, world!");Chant(42);Chant([1, 2, 3]);Whisper
Section titled “Whisper”Prints a value to stdout without a trailing newline.
Whisper("Enter name: ");Inscribe
Section titled “Inscribe”Reads a line of input from stdin.
Whisper("What is your name? ");Runestone name is Inscribe();Chant("Hello, " + name + "!");File I/O
Section titled “File I/O”ReadScroll
Section titled “ReadScroll”Reads the entire contents of a file as a string.
Runestone contents is ReadScroll("data.txt");Chant(contents);WriteScroll
Section titled “WriteScroll”Writes a string to a file, overwriting any existing content.
WriteScroll("output.txt", "Hello from RuneLang!");AppendScroll
Section titled “AppendScroll”Appends a string to a file without overwriting.
AppendScroll("log.txt", "New entry\n");ScrollExists
Section titled “ScrollExists”Returns Truth if a file exists, Falsehood otherwise.
Quest begins when (ScrollExists("config.rune")) Chant("Config found.");elsewise Chant("No config file.");end of QuestReturns the absolute value.
Chant(Abs(-42)); // 42Chant(Abs(42)); // 42Chant(Abs(-3.14)); // 3.14Raises a number to a power. Equivalent to the ** operator.
Chant(Pow(2, 10)); // 1024Returns the square root as a Potion (float).
Chant(Sqrt(144)); // 12Chant(Sqrt(2)); // 1.4142135623730951Min / Max
Section titled “Min / Max”Returns the smaller or larger of two numbers.
Chant(Min(5, 3)); // 3Chant(Max(5, 3)); // 5Floor / Ceil / Round
Section titled “Floor / Ceil / Round”Chant(Floor(3.7)); // 3Chant(Ceil(3.2)); // 4Chant(Round(3.5)); // 4Chant(Round(3.4)); // 3Trigonometry
Section titled “Trigonometry”Chant(Sin(PI / 2)); // 1.0Chant(Cos(0)); // 1.0Chant(Tan(PI / 4)); // ~1.0Natural logarithm (base e).
Chant(Log(EULER)); // 1.0Constants
Section titled “Constants”| Constant | Value | Description |
|---|---|---|
PI | 3.141592653589793 | Pi |
TAU | 6.283185307179586 | Tau (2 * Pi) |
EULER | 2.718281828459045 | Euler’s number (e) |
INFINITY | inf | Positive infinity |
Utility
Section titled “Utility”Measure
Section titled “Measure”Returns the length of a string, array, or map.
Chant(Measure("hello")); // 5Chant(Measure([1, 2, 3])); // 3TypeOf
Section titled “TypeOf”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"Transmute
Section titled “Transmute”Converts a value to a different type.
Transmute(42, "Runestone") // "42"Transmute("123", "Countstone") // 123Transmute(3.14, "Countstone") // 3Transmute(42, "Potion") // 42.0Transmute(1, "Flagstone") // TruthFormat
Section titled “Format”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 + "!");Assert
Section titled “Assert”Throws an error if the condition is Falsehood.
Assert(1 + 1 == 2); // passesAssert(Falsehood); // ERROR: assertion failedImmediately terminates the program.
Halt();Chronos
Section titled “Chronos”Returns the current Unix timestamp in milliseconds.
Potion now is Chronos();Chant("Timestamp: " + now);Slumber
Section titled “Slumber”Pauses execution for the specified number of milliseconds.
Chant("Casting spell...");Slumber(2000); // wait 2 secondsChant("Spell complete!");