Event Aware Rooms

Tutorial by Chris Hunt – nospam@cwhunt.com

in collaboration with Ron Broglio – ron.broglio@lcc.gatech.edu

 

1. Purpose

This patch creates a simple event aware room and shows programmers how to make their rooms respond to player actions.

            Our example room is a Dog Kennel, filled with dogs that bark at any objects, players or otherwise, named ‘Cat’.

 

2. Background

Any programmer can install and use this patch.

We used the @dump command to create a text that will create all the methods for the EventAwareRoom when it is pasted into the MOO space. We also walk the programmer through a simple tutorial for creating their own event-sensitive rooms.

 

3. Implementation

 

3.1 Installing the Basic EventAwareRoom

The first thing we want to do is create a generic EventAwareRoom. This room will be the parent object for any room that will be sensitive (and responsive) to actions occurring within. For now, our room will only detect players entering or leaving; you will be able to add more functionality through other tutorials or exploring the enCore code.

 

First, open the object editor and click ‘Create New Object’. Make it a generic room, and call it EventAwareRoom. Do not connect it to any other rooms, since this will be an ‘abstract’ room—it will only be used to create other objects.

            Your screen should look like this:

 

Figure 3.1

 

Press create. Write down the object number of your new EventAwareRoom. You can find the object number in the upper left hand corner of the object editor when you select the Room from your list of objects.

Figure 3.2

 

Open the program editor. Find the new EventAwareRoom in your list of objects and select it. Check the ‘Read’ and ‘Fertile’ flags, then press ‘Save Object’. Now we configure our installation code to work with your MOO space.

            Open Notepad, Word, or some other application that can search/replace text. Paste the following code into a new window.

 

@verb #EVENTROOM:"enterfunc" this none this

@program #EVENTROOM:enterfunc

pass(@args);

this:onEnter(@args);

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

.

 

@verb #EVENTROOM:"exitfunc" this none this

@program #EVENTROOM:exitfunc

pass(@args);

this:onExit(@args);

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

.

 

@verb #EVENTROOM:"onEnter" any none none rxd

@program #EVENTROOM:onEnter

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

.

 

@verb #EVENTROOM:"onExit" any none none rxd

@program #EVENTROOM:onExit

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

.

 

Run a search for ‘#EVENTROOM’, and replace it with the object number for your EventAwareRoom. For instance, if my new room object had number #17689, I would search for ‘#EVENTROOM’ and replace it with ‘#17689’ (without the quotes, of course).

            Take this updated text and paste it into the MOO command box.

 

Figure 3.3

 

If you created the object properly (and used the right number) you should see something like the following:

 

Figure 3.4

 

3.2 A Sample EventAwareRoom: Dog Kennel

You have installed a generic EventAwareRoom. Now, you can create new EventAwareRooms using the @create command. For our example, we will create a Dog Kennel. Whenever a player named ‘Cat’ enters—or an object named ‘Cat’ is dropped—the dogs will bark every few seconds until the name is changed or the player leaves.

            Type the following command, but replace ‘#EVENTROOM’ with the object number of your EventAwareRoom (#17689 in the example above). Generally, any hash sign, ‘#’, followed by text is a signal for you to insert your actual object number.

 

@create #EVENTROOM named “Dog Kennel”

 

Manually created objects are always placed in your inventory, but this does not make sense for rooms. To properly install your new room into the MOO space, type:

 

@move #MY_NEW_KENNEL to #-1

 

You should visit your room by typing:

 

@go #MY_NEW_KENNEL

 

Once there, you can connect your room to other rooms in the MOO by using the @dig command. However, the @dig command can only create exits for your current room. You will have to visit any connecting rooms and create reciprocal exits.

 

@dig north to #MY_CONNECTED_ROOM

 

Note the direction—‘north’. This direction is not generally important—you could just make all your directions ‘north’ and it would not matter.

 

Now that you have created and connected your new Kennel, we will program it to respond to cats. Open the program editor and view the Kennel object. We will create two new verbs: ‘bark’ and ‘onEnter’.

 

Press ‘New Verb’ and call it ‘bark’. ‘Read’, ‘Execute’, and ‘Debug’ permissions should be set; arguments should be ‘any’, ‘none’, and ‘none’. Insert the following code and press compile:

 

"fork creates a delay--in this case, a random number of seconds 1-10";

fork (random(10))

  "if the object is still in the room AND named 'Cat'";

  if (args[1] in this.contents && args[1].name == "Cat")

     this:announce_all("Dogs say, \"Woof!\"");

     "call the bark timer again";

     this:bark(args[1]);

  endif

endfork

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

 

Your screen should look like this:

 

Figure 3.5

 

Now press ‘New Verb’ again, and call it ‘onEnter’. ‘Read’, ‘Execute’, and ‘Debug’ permissions should be set; arguments should be ‘any’, ‘none’, and ‘none’. Insert the following code and press compile:

 

if (args[1].name == "Cat")

  this:announce_all("Smelling the cat, dogs start barking!");

  this:bark(args[1]);

endif

"Code and tutorial by Chris Hunt -- nospam@cwhunt.com";

"Maintained and published by Dr. Ron Broglio, Georgia Tech";

" ron.broglio@lcc.gatech.edu";

 

Your screen should look like this:

 

Figure 3.6

 

Create a new object named ‘Cat’ and drop it into the Kennel or rename yourself to ‘Cat’ by typing:

 

@rename me to ‘Cat’

 

…now enter the room. The dogs should start barking at you!