external next up previous contents index
Next: 8.7 A crash course Up: Basic MOO Programming Tutorial Previous: 8.5 Social verb tutorial

8.6 [TECFAMOO] ``E_WEB'' Tutorial, Level 0

 

Note: most of that applies to the other E_Web MOOs.

The E_Web interface has a nice object browser. So the first thing you might want to try is simply looking at an object from the web. E.g. if your object is #2108 you can look at it from a www browser with an URL like http://tecfa.unige.ch:7778/objbrowse/2108.

When you access an object via E_Web with an URL like: http://tecfa.unige.ch:7778/4026/ the MOO will return a list of html strings produced by the verb <object>:http_request, in this case: #4026:http:request. If you want to put some simple static information on the Web there are two solutions:

[TECFAMOO] Make a child of of an webbed object

To put html in the .htext property, simply @edit <object>.htext. E.g. look at the http://tecfa.unige.ch:7778/4026/. Note that all objects at TecfaMOO do have an .htext property (that is btw also being used by the WWW Interface). On other E_WEBbed MOOs such a property may or may not exist. If it does not, just write your own :http\_request verb and add a property like .htext to you object.

Write a :http_request verb:

You can write a :http_request verb yourself that will return information that will be displayed to the user. Here is an example which we shall discuss. To see what it does, please have a look at &e_thing test. As an example, here is the code for the Generic E_WEBbed Thing (&_thing).

@program &e_thing:http_request   this none this
 1:  //      A short cut to the html utils
 2:  hu = $ehtml_utils;
 3:  //
 4:  //      Let's return the name of the object as title and main header
 5:  //
 6:  title = this.name;
 7:  lines = {hu:title(title), hu:heading1(title)};
 8:  //
 9:  //    Insert the standard description of the object in <pre> format
10:  //
11:  desc = $list_utils:listify_if_needed(this.description);
12:  lines = {@lines, @hu:pre(desc)};
13:  //
14:  //    Insert the contents of the .htext property
15:  //
16:  if (this.htext)
17:    lines = {@lines, @$list_utils:listify_if_needed(this.htext)};
18:  else
19:    lines = {@lines, "No .htext available - "};
20:  endif
21:  //
22:  //    Insert a pointer to the object browser
23:  //
24:  lines = {@lines, "<hr>", &object_browser:object_anchor(this, 1), "(Inspection)"};
25:  return lines;
26:  /* Last edited on Wed Jan 15 12:36:33 1997 GMT+1 by Kaspar (#85). */
--

Some explanations:

  1. The $e_html_utils contains a collection of useful verbs for generating html. The expression hu = $ehtml_utils; in line 2 will just allow us to use a shortcut later in the code.
  2. Line 7: lines = {hu:title(title), hu:heading1(title)}; generates a list like:
    {"<title>e_thing Test</title>", "<h1>e_thing Test</h1>"}
    that is associated with a variable lines that we shall use to return generated html on line 25
  3. On lines 11 and 12 we generate html to include the standard MOO description (that is stored in the .description property) of the object. The $list_utils:listify_if_needed method will simply test if the argument is a list. If it is not, it will make a list. The expression lines = {@lines, @hu:pre(desc)}; will simple append the elements of ``desc'' (a list of description strings) to the contents of ``lines'' and surround it with HTML <pre> ...</pre> tags. It's a frequently seen pattern in MOO code.
  4. Lines 16 to 20 do something similar with the contents of the .htext property.
  5. Finally, in line 24 we generate a link to the object browser of this object, so that people can look at the code.

As you can see you can return dynamically all sorts of information. As an exercice you now should create an object, e.g. with

@create $thing named My super E_Web object, mseo

Next you can copy the :http_request verb from the Generic E_WEBbed Thing (#4152).

  @copy &e_thing:http_request to xxx:http_request

The you can try to modify the verb, in order to display information differently or add things like the object's location, it's owner and so forth.


next up previous contents index external
Next: 8.7 A crash course Up: Basic MOO Programming Tutorial Previous: 8.5 Social verb tutorial

Daniel K. Schneider
Thu Apr 17 12:43:52 MET DST 1997