Skip to main content

Output Methods

echo

Display messages to the user with script name prefix:
echo "Starting hunting routine"
echo "Health: #{Char.health}", "Mana: #{Char.mana}"

# Output: [script_name: Starting hunting routine]
#         [script_name: Health: 100]
#         [script_name: Mana: 50]

respond

Output directly to the game window without script prefix:
respond "=" * 40
respond "Status Report"
respond "Health: #{Char.health}"
respond "=" * 40
respond can accept arrays and will output each element on a new line.

Echo Control

# Disable echo output
echo_off
toggle_echo

# Re-enable echo output
echo_on

script = Script.current
script.no_echo = true  # Suppress echo output

Game Communication

put

Send commands to the game:
# Single command
put "look"

# Multiple commands
put "north", "look", "south"

# Variable command
command = "attack #{target}"
put command

fput (Force Put)

Send a command and wait for the game to be ready:
# Automatically handles roundtime, stun, etc.
fput "attack troll"

# Wait for specific response
result = fput "search", "You search", "You find nothing"
if result =~ /find nothing/
  echo "Nothing found"
end
fput automatically retries on stun, web, and other temporary conditions.

multifput

Execute multiple forced commands in sequence:
multifput "stand", "north", "look"
# Equivalent to:
# fput "stand"
# fput "north" 
# fput "look"

Waiting for Game Output

waitfor

Wait for specific text from the game:
# Wait for single string
waitfor "Obvious exits"

# Wait for any of multiple strings
line = waitfor "You attack", "You miss", "You fumble"

if line =~ /attack/
  echo "Hit!"
else
  echo "Missed"
end

waitforre

Wait for a regular expression match:
# Wait for pattern
match = waitforre /You (?:hit|strike|slash) the (\w+)/

creature = match[1]
echo "Hit the #{creature}!"

matchwait

Use with match for multiple patterns:
match "success", "You succeed"
match "failure", "You fail" 
match "retry", "Try again"
result = matchwait

case result
when /You succeed/
  goto :success
when /You fail/
  goto :failure
when /Try again/
  goto :retry
end

matchtimeout

Wait with a timeout:
result = matchtimeout(5, "You succeed", "You fail")

if result == false
  echo "Timed out after 5 seconds"
else
  echo "Got result: #{result}"
end

Buffer Management

get / get?

Retrieve lines from the script’s input buffer:
# Blocking get (waits for line)
line = get
echo "Received: #{line}"

# Non-blocking get (returns nil if empty)
line = get?
if line
  echo "Got: #{line}"
else
  echo "Buffer is empty"
end

clear

Clear and return the script’s input buffer:
put "inventory"
pause 0.5

lines = clear
lines.each { |line| echo line }

reget

Retrieve recent game output:
# Get last 10 lines
recent = reget(10)

# Get lines matching pattern
matches = reget(50, "monster", "creature")

# Get all history including wrapped lines
all_history = regetall(100)

Script Control

pause

Sleep for a duration:
# Seconds
pause 5

# Minutes
pause "2m"

# Hours
pause "1h"

# Days  
pause "1d"

# Decimal values
pause 0.5  # Half second

wait_while / wait_until

Wait for conditions:
# Wait while condition is true
wait_while { stunned? }
wait_while { Char.mana < 50 }

# Wait until condition is true
wait_until { Char.health > 80 }
wait_until { !checkwebbed }

# With message
wait_until("Waiting for health...") { Char.health > 80 }

Roundtime Management

waitrt / waitrt?

# Wait for roundtime to expire
waitrt

# Check and wait, returns true if there was RT
if waitrt?
  echo "Had roundtime"
end

# Check remaining roundtime
remaining = checkrt
echo "#{remaining} seconds remaining"

Cast Roundtime

# Wait for cast roundtime
waitcastrt

# Check and wait
if waitcastrt?
  echo "Had cast RT"
end

# Check remaining
remaining = checkcastrt

Movement

move

Intelligent movement with automatic retries:
# Basic movement
move "north"

# Returns true on success, false/nil on failure
if move "go door"
  echo "Moved successfully"
else
  echo "Movement failed"
end

# Handles:
# - Climbing
# - Swimming  
# - Roundtime
# - Stun
# - Web
# - Locked/closed doors

multimove

Move through multiple directions:
multimove "north", "north", "east", "up"
# Or
multimove n, n, e, u

Direction Helpers

# Short direction methods
n    # "north"
s    # "south"
e    # "east"
w    # "west"
ne   # "northeast"
se   # "southeast"
sw   # "southwest"
nw   # "northwest"
u    # "up"
d    # "down"
o    # "out"

# Usage
move n
multimove n, n, e, u

Status Checks

Character State

# Status indicators
checkstunned      # Stunned?
checkwebbed       # Webbed?
checkdead         # Dead?
checkbleeding     # Bleeding?
checkprone        # Lying down?
checkstanding     # Standing?
checksitting      # Sitting?
checkkneeling     # Kneeling?
checkhidden       # Hidden?
checkinvisible    # Invisible?

# Combined checks
muckled?          # Dead, stunned, or webbed?

Room Checks

# Room information
checkroom         # Room title
checkarea         # Area name
checkroomdescrip  # Room description
checkpaths        # Available exits

# Examples
if checkroom("Town Square")
  echo "In town square"
end

exits = checkpaths
echo "Exits: #{exits.join(', ')}"

NPCs and PCs

# Check for creatures
creatures = checknpcs
if creatures
  echo "Found: #{creatures.join(', ')}"
end

# Check for players
players = checkpcs
if players
  echo "Players here: #{players.join(', ')}"
end

# Check for specific creature
if checknpcs("troll", "ogre")
  echo "Dangerous creature present!"
end

Inventory Checks

# Check hands
right = checkright
left = checkleft

echo "Right hand: #{right || 'empty'}"
echo "Left hand: #{left || 'empty'}"

# Check for specific item
if checkright("sword")
  echo "Holding sword"
end

Variable Access

# Get script arguments
vars = variable
echo "Args: #{vars.inspect}"

# Equivalent to
script = Script.current
echo "Args: #{script.vars.inspect}"

Unique Buffer

Communicate between scripts:
# Send to another script
send_to_script("other_script", "message1", "message2")

# In other_script:
line = unique_get      # Blocking
line = unique_get?     # Non-blocking

# Wait for specific message
result = unique_waitfor("ready", "done")

Upstream Communication

Capture user input:
# Enable upstream capture
toggle_upstream

loop do
  user_input = upstream_get
  echo "User typed: #{user_input}"
  
  # Process and optionally modify
  if user_input =~ /^attack/
    echo "Intercepted attack command"
  end
end

Script Silence

# Make script completely silent
silence_me

# Toggle back
silence_me

script = Script.current
script.silent = true

Practical Examples

Combat Loop

loop do
  waitrt?
  target = checknpcs("troll", "ogre")
  
  if target
    fput "attack #{target}"
  else
    echo "No targets, waiting..."
    pause 2
  end
end

Healing Script

loop do
  if Char.health < 50
    echo "Health low, healing..."
    fput "drink my potion"
    waitfor "You feel better"
  end
  
  pause 5
end

Room Navigation

target_room = "Bank"

loop do
  current = checkroom
  echo "Currently in: #{current}"
  
  if current =~ /#{target_room}/
    echo "Arrived!"
    break
  end
  
  # Smart room navigation logic here
  pause 1
end

Next Steps

Script Lifecycle

Learn about script startup and termination

Hooks

Intercept and modify game data

Threading

Create multi-threaded scripts

Build docs developers (and LLMs) love