Table of Contents
Introduction
The core I/O loop in Agony Forge handles input from users, processes it, and sends output back to them. Fundamentally that's all a MUD, or any command line interface, is. Within that process here are the most important objects to be familiar with.
Input and Output
The lowest level objects for I/O in Agony Forge are Input and Output. Whenever a user types something in and their computer sends it to the server, it is received as an Input. Whenever the game wants to send something to a user's client, you build an Output object to hold it.
Input is an extremely simple object that just holds a String inside it.
Output is a little more complex because it holds a list of String objects but also has some convenience methods for appending strings together and formatting them.
Each time you append to an Output it is treated as a new line of text. You can quickly assemble multiple lines of output by appending Output objects together, and you can include variables the same way you can using String.format() on a normal Java String.
You can easily embed colors into your output with color codes. The supported color codes can be found in the Color enum. To embed them in an Output just enclose them in square brackets, like this:
output.append("The following will be [blue]blue[default]!");
The text in between [blue] and [default] would appear blue once it is sent to the user, and the rest would be the default color.
Questions and Responses
When a new user first connects they are met with a prompt, called a Question. Their answer to the question is a Response. The loop is simply that the MUD asks questions and the user gives responses. You can find the code that makes this work in WebSocketController.onInput() where it receives Input from the user. The Input is just the string that they typed. It packages that with some other information into a Response and passes it to whatever their current Question is. The Question can be most anything from a menu to a command line interpreter or anything else that processes some input and generates some output. In most cases a MUD would start with a menu to ask the user for some information such as which character they'd like to play, and then moves on to a command interpreter that lets the character explore the world.
Question objects process input from the user, but also have the ability to change the user's "current" Question to a different one. That's how the user moves between different menus, editors, or modes in their command interpreter. Depending on what is received from the user, a Question may stay the same or change to a new Question once it has processed the user's command.