Scripting Library

Learn to write your own TradeWars scripts

The Rules

Brandon's rules for scripts that don't get you killed:

Lesson 1: Send and Wait

Every script does two things: send a command, wait_for the response.

# Wait for the command prompt, then send a command
wait_for("Command [TL=00:00:00]:[1]?")
send("I")

# Wait for the info menu, then go back
wait_for("Information")
send("Q")

The wait_for looks at what the game actually sent. The send types your command. That's it. Everything else is just repeating this pattern.

Lesson 2: Reading the Screen

Your script sees what you see. Learn the prompts:

Match on the exact text. If the game says "Command" and you wait for "command" (lowercase), it won't match. Case matters.

Lesson 3: The Termux Helper

Our tw.py helper gives you:

Download: coming soon. Check back after release.

Lesson 4: Your First Script

A port trader — buys and sells at the current sector's port:

#!/usr/bin/env python3
# port_trade.py - simple buy/sell loop

wait_for("Command")
send("P")           # Port menu
wait_for("Commerce report")
send("S")           # Sell everything
wait_for("How many holds")
send("9999")        # All holds
wait_for("Commerce report")
send("B")           # Buy
wait_for("How many holds")
send("9999")
wait_for("Commerce report")
send("Q")           # Leave port
wait_for("Command")
print("Trade complete.")

Run it with !port_trade.py from the helper. Watch it work. Then modify it. That's how you learn.

More Lessons

Under construction. Coming next: