LLFS Language Specification - wwestlake/Labyrinth GitHub Wiki

LLFS Language Specification

LLFS is a simplified, shell-like language used for interacting with the Labyrinth MUD environment. LLFS supports basic command structures, variable assignment, and conditional logic, allowing players and scripts to interact with the game world in a flexible manner. LLFS is designed to be intuitive and simple while providing the core functionality needed to play and script in the game world.


1. Basic Syntax

  • Comments: LLFS allows single-line comments.
# This is a comment
  • Commands: A command is invoked by typing the command name followed by its parameters. Parameters can be constants, variables, or expressions.

Example:

go west
attack $(target)

2. Variables

Variables in LLFS are prefixed with a $ and enclosed in parentheses when used in expressions. Variables can store any valid command result, literal, or expression result.

  • Variable Declaration:

Variables are dynamically typed, assigned with the = operator.

strength = get $(character.strength)
target = "orc"
direction = "north"
  • Variable Usage:

Variables are referenced by their name within $().

go $(direction)
print $(strength)

3. Supported Commands

3.1 Movement Commands

Used to navigate the game world.

  • go <direction | exit name>: Moves the character in the specified direction or through a specific exit.

Examples:

go north
go west
go $(direction)

3.2 Interaction Commands

Used to interact with characters, objects, and the environment.

  • attack : Attacks a specified target.

Examples:

attack orc
attack $(target)
  • take : Takes an item from the environment.

Examples:

take sword
take $(item)
  • drop : Drops an item.

Examples:

drop sword
drop $(item)
  • give to : Gives an item to another character.

Examples:

give sword to orc
give $(item) to $(target)

3.3 Utility Commands

Used for various utility functions.

  • print : Outputs the value of an expression.

Examples:

print $(strength)
print "Hello World"
  • wait : Waits for the specified number of seconds before continuing.

Examples:

wait 5
wait $(delay)
  • get : Retrieves the value of a character attribute, object property, or environment variable.

Examples:

get $(character.health)
get $(object.description)
  • set = : Sets an attribute or property to a specific value.

Examples:

set $(character.strength) = 10
set $(object.color) = "red"

4. Control Flow

LLFS supports basic control flow constructs for logic and decision making.

4.1 If Statements

Executes a command or block of commands if a condition is true.

Syntax:

if <condition> {
    <commands>
}

Examples:

if $(strength) > 10 {
    attack orc
}

4.2 Loops

Executes a block of commands repeatedly until a condition is met.

  • while : Repeats a block of commands while the condition is true.

Syntax:

while <condition> {
    <commands>
}

Example:

while $(health) < 100 {
    heal $(character)
}

5. Expressions and Arithmetic

LLFS supports basic arithmetic and logical expressions.

5.1 Arithmetic

LLFS supports addition, subtraction, multiplication, and division.

Examples:

a = 5 + 3
b = $(a) * 2
c = $(b) / 4

5.2 Comparisons

Comparisons return true or false and can be used in control flow statements.

  • Operators: ==, !=, <, >, <=, >=

Example:

if $(strength) > 10 {
    attack dragon
}

5.3 Logical Operators

  • and, or, not: Used to combine or negate conditions.

Example:

if $(health) < 50 and $(enemyNearby) {
    run
}

6. Function Definitions

Functions in LLFS allow you to define reusable blocks of code. Functions can take parameters and return values.

6.1 Function Declaration

Functions are defined using the function keyword.

Syntax:

function <function_name>(<params>) {
    <commands>
}

Example:

function healSelf() {
    while $(health) < 100 {
        heal $(character)
    }
}

6.2 Function Invocation

Functions are invoked by calling their name with arguments if necessary.

Example:

healSelf()

7. Error Handling

LLFS supports basic error handling using the try and catch blocks.

Syntax:

try {
    <commands>
} catch {
    <error_handling_commands>
}

Example:

try {
    attack $(enemy)
} catch {
    print "Attack failed!"
}

8. Command Output and Return Values

Commands can return values that can be stored in variables for later use.

Example:

strength = get $(character.strength)
print $(strength)

9. Events and Triggers

LLFS supports defining event listeners for specific triggers.

Syntax:

on <event> {
    <commands>
}

Example:

on enemy_approaches {
    attack $(enemy)
}

10. File Operations

LLFS includes commands for reading and writing to files.

  • readFile : Reads content from a file.

    Example:

    content = readFile "data.txt"
    print $(content)
    
  • writeFile : Writes content to a file.

    Example:

    writeFile "output.txt" $(content)
    

11. Command and Variable Scoping

LLFS supports block scoping for variables. Variables declared inside a block are not accessible outside that block.

Example:

if $(isAlive) {
    health = get $(character.health)
}
print $(health) # Error: health is out of scope

12. Chaining Commands

LLFS allows chaining multiple commands on the same line using a semicolon (;).

Example:

go north; attack orc; print "Battle started"
⚠️ **GitHub.com Fallback** ⚠️