LLFS Language Specification - wwestlake/Labyrinth GitHub Wiki
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.
- 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)
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)
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)
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)
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"
LLFS supports basic control flow constructs for logic and decision making.
Executes a command or block of commands if a condition is true.
Syntax:
if <condition> {
<commands>
}
Examples:
if $(strength) > 10 {
attack orc
}
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)
}
LLFS supports basic arithmetic and logical expressions.
LLFS supports addition, subtraction, multiplication, and division.
Examples:
a = 5 + 3
b = $(a) * 2
c = $(b) / 4
Comparisons return true or false and can be used in control flow statements.
-
Operators:
==
,!=
,<
,>
,<=
,>=
Example:
if $(strength) > 10 {
attack dragon
}
- and, or, not: Used to combine or negate conditions.
Example:
if $(health) < 50 and $(enemyNearby) {
run
}
Functions in LLFS allow you to define reusable blocks of code. Functions can take parameters and return values.
Functions are defined using the function
keyword.
Syntax:
function <function_name>(<params>) {
<commands>
}
Example:
function healSelf() {
while $(health) < 100 {
heal $(character)
}
}
Functions are invoked by calling their name with arguments if necessary.
Example:
healSelf()
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!"
}
Commands can return values that can be stored in variables for later use.
Example:
strength = get $(character.strength)
print $(strength)
LLFS supports defining event listeners for specific triggers.
Syntax:
on <event> {
<commands>
}
Example:
on enemy_approaches {
attack $(enemy)
}
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)
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
LLFS allows chaining multiple commands on the same line using a semicolon (;
).
Example:
go north; attack orc; print "Battle started"