Skip to main content

Overview

The Room class (aliased as Map) provides access to current room information, room database lookups, and navigation data. It tracks your location and provides methods to query room properties, find paths between rooms, and access the map database. Room information includes:
  • Room ID and unique identifier (UID)
  • Title and description
  • Available exits (paths)
  • Location name
  • Climate and terrain
  • Navigation data (wayto/timeto)
  • Room tags and classifications

Quick Start

# Get current room
room = Room.current
echo "Current room: #{room.title[0]}"
echo "Room ID: #{room.id}"
echo "Exits: #{room.paths.join(', ')}"

# Look up room by ID
room = Room[12345]

# Look up by UID
room = Room['u123456']

# Find room by title
room = Room['Town Square']

Room Attributes

id
Integer
Internal map database room ID
uid
Array<Integer>
Unique identifiers from the game (may have multiple values for multi-UID rooms)
title
Array<String>
Room titles (array to handle multiple titles for the same room)
description
Array<String>
Room descriptions (array to handle variations)
paths
Array<String>
Available exits (e.g. [“north”, “south”, “east”, “west”, “gate”])
location
String
Named location (e.g. “Wehnimer’s Landing”, “River’s Rest”)
climate
String
Climate classification (e.g. “temperate”, “cold”)
terrain
String
Terrain type (e.g. “town”, “forest”, “mountain”)
wayto
Hash
Hash mapping destination room IDs to movement commands
timeto
Hash
Hash mapping destination room IDs to travel time estimates
tags
Array<String>
Classification tags (e.g. [“bank”, “shop”, “node”, “danger”])

Class Methods - Current Room

Room.current

Returns the current room object.
room = Room.current

if room
  echo "You are in: #{room.title[0]}"
  echo "Room ID: #{room.id}"
  echo "UID: #{room.uid.join(', ')}"
  echo "Exits: #{room.paths.join(', ')}"
else
  echo "Current room not found in map database"
end
return
Room
Current room object, or nil if not found

Room.previous

Returns the previous room you were in.
prev = Room.previous

if prev
  echo "You came from: #{prev.title[0]}"
end
return
Room
Previous room object, or nil

Room.current_or_new

Returns the current room, or creates a temporary new one if not in database.
room = Room.current_or_new
echo "Current location: #{room.title[0]}"
return
Room
Current room object (always returns a room)

Class Methods - Lookup

Room[val]

Looks up a room by ID, UID, title, or description.
val
Integer | String
required
Room ID (Integer), UID string (“u12345”), or search string
# By room ID
room = Room[12345]

# By UID
room = Room['u123456']

# By title
room = Room['Town Square']

# By description fragment
room = Room['stone archway']
return
Room
Room object, or nil if not found

Room.list

Returns all rooms in the map database.
echo "Total rooms: #{Room.list.compact.size}"

# Find all banks
banks = Room.list.select { |r| r && r.tags.include?('bank') }
banks.each { |room| echo "Bank: #{room.title[0]}" }
return
Array<Room>
Array of all Room objects

Class Methods - Special Lookups

Room.tags

Returns all unique tags used in the map database.
Room.tags.each do |tag|
  echo "Tag: #{tag}"
end
return
Array<String>
Array of all unique room tags

Room.locations

Returns all unique location names.
Room.locations.each do |loc|
  echo "Location: #{loc}"
end
return
Array<String>
Array of all location names

Room.get_location

Uses the in-game LOCATION command to get your approximate coordinates.
loc = Room.get_location
if loc
  echo "You are near: #{loc}"
else
  echo "Unable to determine location"
end
return
String | false
Location string from the game, false if unable to determine, or nil if no script context

Instance Methods

to_s

Returns a formatted string representation of the room.
room = Room.current
echo room.to_s
# Output:
# #12345 (u123456):
# Town Square (Wehnimer's Landing)
# You are standing in the town square...
# north, south, east, west
return
String
Formatted room information

Working with Navigation

wayto

The wayto hash maps destination room IDs to the commands needed to get there.
room = Room.current

room.wayto.each do |dest_id, command|
  dest = Room[dest_id]
  echo "To #{dest.title[0]}: #{command}"
end
# Check if you can move to a specific room
dest_id = 12346
if room.wayto[dest_id]
  fput room.wayto[dest_id]
else
  echo "No direct path to room #{dest_id}"
end

timeto

The timeto hash maps destination room IDs to estimated travel time (or Proc objects for complex calculations).
room = Room.current

room.timeto.each do |dest_id, time|
  dest = Room[dest_id]
  
  if time.is_a?(Proc)
    echo "To #{dest.title[0]}: calculated time"
  else
    echo "To #{dest.title[0]}: #{time} seconds"
  end
end

Working with Tags

Finding tagged rooms

Tags classify rooms by type and features.
# Find all shops
shops = Room.list.select { |r| r && r.tags.include?('shop') }
shops.each { |shop| echo "Shop: #{shop.title[0]} (#{shop.id})" }

# Find all banks
banks = Room.list.select { |r| r && r.tags.include?('bank') }

# Find nodes (mana regeneration spots)
nodes = Room.list.select { |r| r && r.tags.include?('node') }

# Find dangerous areas
danger = Room.list.select { |r| r && r.tags.include?('danger') }

Checking current room tags

room = Room.current

if room.tags.include?('bank')
  echo "You're in a bank"
end

if room.tags.include?('town')
  echo "You're in town (safe area)"
end

if room.tags.include?('shop')
  echo "You're in a shop"
end

Examples

Display current location info

room = Room.current

if room
  echo "==== Current Location ===="
  echo "Title: #{room.title[0]}"
  echo "ID: #{room.id}"
  echo "UID: #{room.uid.join(', ')}"
  echo "Location: #{room.location}"
  echo "Exits: #{room.paths.join(', ')}"
  echo "Tags: #{room.tags.join(', ')}" if room.tags.any?
else
  echo "Current room not mapped"
end

Find nearest bank

current = Room.current
if current
  banks = Room.list.select { |r| r && r.tags.include?('bank') }
  
  if banks.any?
    # Simple proximity check by room ID difference
    nearest = banks.min_by { |bank| (bank.id - current.id).abs }
    echo "Nearest bank: #{nearest.title[0]} (Room #{nearest.id})"
  else
    echo "No banks found in map"
  end
end

List available exits with descriptions

room = Room.current

if room
  echo "Available exits from #{room.title[0]}:"
  
  room.wayto.each do |dest_id, command|
    dest = Room[dest_id]
    if dest
      echo "  #{command.ljust(15)} -> #{dest.title[0]}"
    else
      echo "  #{command.ljust(15)} -> Unknown room"
    end
  end
end

Check if in a safe area

room = Room.current

if room
  safe_tags = ['town', 'bank', 'shop', 'inn']
  is_safe = room.tags.any? { |tag| safe_tags.include?(tag) }
  
  if is_safe
    echo "You are in a safe area"
  else
    echo "You are in the wilderness - be careful!"
  end
end

Track room changes

last_room_id = nil

loop do
  current = Room.current
  
  if current && current.id != last_room_id
    prev = Room.previous
    
    echo "\nEntered: #{current.title[0]} (#{current.id})"
    echo "From: #{prev.title[0]}" if prev
    
    last_room_id = current.id
  end
  
  sleep 0.1
end

Notes

  • Room data must be loaded from the map database before use
  • Room.current may return nil if the current room is not in the database
  • Multi-UID rooms have arrays for uid, title, and description to handle variations
  • The wayto hash may contain strings (simple commands) or Proc objects (complex movement)
  • Map data is game-specific - GemStone IV uses different structures than DragonRealms

Build docs developers (and LLMs) love