Learning LPC Programming
LPC is a powerful object-oriented language purpose-built for MUD development and interactive fiction. Create dynamic game worlds with real-time command processing and rich object systems.
Why Learn LPC?
- Purpose-built for games: Designed specifically for MUD development and interactive worlds
- Object-oriented: Rich object system with inheritance and method overriding
- Real-time processing: Built-in support for asynchronous events and timers
- Persistent worlds: Native support for saving game state and objects
LPC vs Other Game Languages
| Feature | LPC | C#/Unity | Python | GDScript |
|---|---|---|---|---|
| Purpose | MUDs | 3D Games | General | 2D/3D Games |
| Learning Curve | Moderate | Moderate | Gentle | Gentle |
| Persistence | Native | Manual | Manual | Manual |
| Community Size | Small | Massive | Massive | Growing |
Your Learning Path
Follow this structured progression to master LPC. Each step builds on the previous one.
2 hours
3 hours
2 hours
2 hours
3 hours
3 hours
3 hours
4 hours
Interactive Lessons
Click each lesson to expand and learn. LPC syntax is similar to C, making it accessible to programmers familiar with C-like languages.
Basic Syntax & Data Types
LPC uses a C-like syntax with strong typing. This lesson covers the fundamental types and syntax rules you'll use in every LPC program.
Primitive Types
int- Integer numbersstring- Text stringsobject- Reference to another LPC objectvoid- No return value
Variable Declaration & Assignment
int health = 100;
string name = "Wizard";
object *inventory; // Array of objects
Comments
// Single-line comment
/* Multi-line
comment */
Type Conversion
int x = 42;
string s = to_string(x);
int y = to_int("100");
Key Takeaway: Strong typing in LPC prevents many bugs. Always declare your types explicitly.
Objects & Inheritance
Objects are the core of LPC. Everything in an LPC MUD is an object. Learn how to create objects and use inheritance to build hierarchies.
Creating a Simple Object
#pragma strict_types
#include "/include/globals.h"
inherit "/std/object";
void create() {
::create();
set_name("sword");
set_id(({{ "sword", "blade" }}));
set_short("a long sword");
}
Object Inheritance
inherit "/std/monster";
void create() {
::create();
set_race("orc");
set_gender("male");
set_body_type("humanoid");
}
Common Methods
void init() {
add_action("look_fn", "look");
}
int look_fn(string str) {
write("You examine: " + str);
return 1;
}
Key Takeaway: Inheritance is crucial for code reuse. Build a solid object hierarchy.
Properties & Methods
LPC uses properties (member variables) and methods to define object behavior. Visibility controls access.
// Object properties
private int hitpoints;
public string name;
static int total_kills;
// Getter/setter methods
int query_hp() { return hitpoints; }
void set_hp(int new_hp) {
if (new_hp < 0) new_hp = 0;
if (new_hp > 100) new_hp = 100;
hitpoints = new_hp;
}
// Initialization
void create() {
name = "Adventurer";
hitpoints = 100;
}
Control Structures
LPC provides familiar C-style control structures for conditional logic and loops.
// If/else
void check_health(int hp) {
if (hp > 75) {
write("You feel great!");
} else if (hp > 25) {
write("Wounded.");
} else {
write("Near death!");
}
}
// Switch
void handle_command(string cmd) {
switch(cmd) {
case "north": move_player("north"); break;
case "south": move_player("south"); break;
default: write("Unknown command.");
}
}
// For loop
void list_inventory(object *items) {
for (int i = 0; i < sizeof(items); i++) {
write(items[i]->query_name());
}
}
Living Objects & Verbs
Living objects represent players and NPCs. Verbs are commands that objects respond to via add_action.
inherit "/std/living";
void create() {
::create();
set_name("goblin");
set_short("a small goblin");
set_hp(50);
}
void init() {
::init();
add_action("do_poke", "poke");
}
int do_poke(string str) {
if (!str || str != "goblin") return 0;
write("You poke the goblin.");
this_object()->attack_object(this_player());
return 1;
}
Events & Signals
LPC provides events and timing mechanisms through signals, heart beats, and alarms.
// Heart beat (periodic events)
void create() {
set_heart_beat(2); // Every 2 seconds
}
void heart_beat() {
// Called every 2 seconds
if (query_hp() < query_max_hp()) {
set_hp(query_hp() + 1);
}
}
// Call out (delayed execution)
void delayed_message() {
write("Now!");
}
void init() {
write("Wait for it...");
call_out("delayed_message", 3); // Call after 3 seconds
}
// Remove scheduled call
int alarm_id;
void cancel_alarm() {
remove_call_out(alarm_id);
}
File I/O & Persistence
LPC provides save_object and restore_object for easy persistence, plus file operations.
// Save object state
string name;
int level;
int gold;
void save_player() {
save_object("/data/players/" + name);
}
// Restore object state
void restore_player(string player_name) {
name = player_name;
restore_object("/data/players/" + name);
}
// File operations
void write_log(string message) {
write_file("/log/game.log", message + "\n");
}
string read_data() {
return read_file("/data/config.txt");
}
string *read_lines() {
return explode(read_file("/data/items.txt"), "\n");
}
Advanced Topics
Lesson content placeholder. Topics: closures, mapping, arrays, advanced control flow.
Curated Repositories
Practice Projects
Build your first MUD objects with these progressive projects:
-
1. Simple Item Object
Create a basic item (sword, scroll, potion) that players can pick up and drop. Implement look, get, and drop commands.
Key Concepts: Objects, init(), add_action, properties -
2. Monster/NPC Object
Build a living NPC with health, combat stats, and basic AI. Implement attacks and healing.
Key Concepts: Living objects, heart_beat, combat system -
3. Room with Objects
Create a room with interconnected exits, items, and NPCs. Players should be able to navigate and interact.
Key Concepts: Room objects, exits, inventory management -
4. Spell or Skill System
Implement a spell casting system with mana, cooldowns, and effects. Add multiple spells with different properties.
Key Concepts: Magic system, timers, events -
5. Complete Game Zone
Build a mini game zone with multiple rooms, NPCs, quests, and combat encounters. Save player progress.
Key Concepts: Full MUD zone, persistence, quest system
Resources Hub
LPC Documentation
Popular MUD Engines
Learning Resources
Community
Tools & IDEs
Related Topics
Your Progress
Check off lessons as you complete them. Your progress is saved locally in your browser.