Phantasmal MUD Lib for DGD
|
Phantasmal Site > DGD > DGD Reference Manual (legacy) > Sending Output to the User 3.5 Sending Output to the UserIn your code statements, you can also use a variable called user. That variable represents the current user object, which is the network connection that you have to the DGD server. There are certain functions you can call on it to do various things. First, try typing code user->query_conn(). You should see a result like $25 = </kernel/obj/telnet#20>. This means that history variable $25 holds a clone of the /kernel/obj/telnet object. That clone is the object that DGD considers the connection object. If you type code query_ip_name(user->query_conn()), you should see either $26 = "localhost" or a similar result with your computer's hostname. If you type code query_ip_number(user->query_conn()), you should see a similar result with "127.0.0.1" or your computer's IP address. If you don't know what a hostname or IP address is, you should probably learn that before running your own MUD... Both are used by internet-connected machines to locate other internet-connected machines. Another interesting thing you can do with the user object is to send output to it. For instance try typing user->message("Bob!\n");. You should see the word "Bob!" on a line by itself, and the history variable will have a value of nil. If you remember, nil was the value that a string has before it gets initialized. It's also the value that a function returns if you don't specifically return anything at all. The backslash and n after "Bob!", above, are a character escape. A character escape is composed of an escape character, which is the backslash, followed by another character, in this case an 'n' for the newline character. There are certain other character escapes that have meaning, such as \b for backspace, \r for a carriage return and \t for a tab. Since the backslash and the double-quote have special meaning in strings, there are special character escapes to write them as well — \\ and \", respectively. Note that with some MUD libraries you'll need to write an end-of-line as \n\r or \r\n. So if your telnet is doing odd things at line endings, try that. You may also want to see if there's an option in your telnet client for treating line endings differently. Many telnet clients (including PuTTY on Win32) support changing the behavior with an option. To see more of how the newline character works, try adding more \n characters. Type code user->message("Line...\n\n\n\n"). If you leave the semicolon off like that, you won't get nil returned, but rather the number 1. That's because the user->message function returns an integer, which is either 1 or 0 for whether the entire message could be sent. When you printed a message with more than one \n, you saw more than one line of space before the returned value. That's because the user->message function writes the output directly to your terminal, and it does it immediately. So you could use it to print fancier output if you wanted to. Anything you print won't be saved to a history variable, so make sure you're okay with it only being on the screen. There's way for DGD to get it back and play with it more.
|