Skip to content

Programmer's Manual

Chris Dosé edited this page Apr 21, 2016 · 10 revisions

NOTE: these wiki pages are out of date!

This document should describe:

  • How to get to the editor
  • What you can and can't do from the editor and from the client
  • How the command parser works; in depth
  • How verbs are searched for; in depth
  • The context variables available to verb code
  • Finding objects
  • Built in attributes
  • Properties
  • Built in functions
  • Adding verbs

It should not be specific to any database, but should include examples from the example database.


Programmers in room.js are any players that have the isProgrammer bit set to true. Only another programmer can do this for you. The seed database that comes with the source code comes with one player who is also a programmer. Use these credentials to log in as him: username: root, password: p@ssw0rd.

Additionally, there is a live demo running at http://rjs.infinitymotel.net/ where every player is treated as a programmer.

Eval

Room.js programmers have access to the eval command. It will evaluate any javascript code (use evalc for coffeescript) and show you the output. Try it like this: eval 2+2.

Eval works similarly to, but not quite like, a javascript/coffeescript repl. It will evaluate statements, but won't keep track of any assignments. eval x = 42 will work, but a subsequent statement eval x + 10 will cause a ReferenceError, as x is not defined.

The eval context has several variables and functions defined. The most important and relevant right now are:

  • player: this is you, the player running the command. (also this in eval context)
  • $: this is a function that lets you get a reference to an object if you know its ID. (e.g. eval $('#wizard') will get you the root player in the example database.)
  • list: this function will list all objects in the database.
  • search: this function will search for objects that contain the string passed in in their names.

Objects in room.js are mutable in the standard way you would expect a js object to behave:

> eval player.foo = "bar"
"bar"
> eval player.foo
"bar"
> eval delete player.foo
true
> eval player.foo
undefined

The Command Parser

To understand how to create new content inside a room.js server, we first need to understand the command parser. The command parser in room.js is pretty basic; this is how it works step by step:

  1. It takes the first word in your command and treats that as the verb.
  2. It reads the rest of the command and looks for prepositions like at, in, inside of.
  3. Everything to the left of the preposition is considered the direct object.
  4. Anything to the right is considered the indirect object.

Examples:

  • look
  • verb: look
  • examine the sword
  • verb: examine
  • direct object: the sword
  • take the sword from the stone
  • verb: take
  • direct object: the sword
  • preposition: from
  • indirect object: the stone

Try it out yourself by running: eval parse "take the sword from the stone".

Object Matching

The command parser just extracts strings from the command. Now we need to actually find objects matching those string descriptions. Objects are searched for in two places:

  1. Objects you are holding.
  2. Objects in the location you are in.

Objects are matched by comparing the search string with the name of each object and all of its aliases.

Now we have a list of objects that were mentioned in the command. Add to that list the current player (you) and the location the player is in. We use this list of objects to search for the verb to be executed.

Matching Verbs

Verbs are the actual actions that you want your player to perform. They are attached to objects in the world, and are found (and then executed) after you enter a command. The previous section described how the server finds all objects mentioned in a command. The server then searches all those objects in a specific order (described below) and executes the first verb that it finds.

  1. The player
  2. The location the player is in
  3. The direct object
  4. The indirect object

Verb Execution

TODO

Clone this wiki locally