-
Notifications
You must be signed in to change notification settings - Fork 17
Programmer's Manual
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.
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. (alsothis
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
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:
- It takes the first word in your command and treats that as the
verb
. - It reads the rest of the command and looks for prepositions like
at
,in
,inside of
. - Everything to the left of the preposition is considered the
direct object
. - 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"
.
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:
- Objects you are holding.
- 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.
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.
- The player
- The location the player is in
- The direct object
- The indirect object
TODO