IntroductionScripting in KAMS is accomplished via
reactions to events. Typically, events which occur in a room are broadcast to everything in the room. Objects can then react to the event. Only objects which mix in the
Reacts module can have reactions, but if you set up reactions in-game for an object, the Reacts module will automatically be added to the object, so you can have individual objects that react without having all objects of that type have the overhead of reacting.
Scripts for reactions are kept in the objects/reactions directory and end in the '.rx' extension. These are just plain-text files which contain instructions on what events to react to and how to react. Any object can use any reaction file or files. Note, however, that once an object loads the reaction file the reactions are stored with the object and subsequent changes to the file will not be reflected in the object unless it is explicitly reloaded.
ReactionsEach reaction has three parts: a list of actions, a test, and the reaction itself. The list of actions narrows down which events will be reacted to. The test provides another check before the reaction is executed. This is usually used to see if the event concerns the current object or not. The reaction itself is the code which will be executed if the test returns true.
ActionsThis is a just a space-separated list of actions. It looks like:
!action
smile bow hi
TestThe test should be a short piece of Ruby code which returns a boolean. This can be multiple lines.
!test
object_is_me? event
ReactionThis is Ruby code which will be executed in the context of the object which is reacting. Currently, and rather dangerously, this means reactions have full access to the server and could really mess things up. So, don't accept reactions from strangers

Reactions look like:
!reaction
"say Hello, there."
All reactions have access to at least the following variables:
- event - the event it is reacting to
- self - the current object
- room - where the event is occurring
- info - the object's Info object
- $manager - the server's manager
The reaction should have a string or nil as its last value (like a return value in Ruby). If the value is a string, it will be parsed as a command. If successful, this command will then be run as an event.
Matching ReactionsAll reactions which match an event and whose test passes will be executed. The reactions are executed after all matches are made. This means you may have multiple reactions which fire for the same event.
Future EventsFuture events are events which are executed after some delay. These can be created very simply with the
after command. There are two forms: one which takes an event and one which takes a block of code.
First form:
after 1, :sec, event
The first parameter is how long to wait, the second parameter is the unit of time, and the third is the event to execute. But it is typically easier to use this form:
after 1 do
"say hello!"
end
If the code block returns a string, it will be parsed as a command. If it returns an event, the event will be added to the queue. Otherwise, whatever the code does is what it does.
Multiple EventsThere are other ways to make the object react. One way is to parse a string into a command using the CommandParser and then manually output the resulting event. This works like so:
event = CommandParser.parse(self, "say hello")
add_event event
Note that any events resulting from reactions will be executed when the reaction is completely finished.
Administrator CommandsReactions can be managed in-game using the
AREACT commands.
Useful ThingsEvery GameObject has its own Info object, so use the
info object to store arbitrary data.
object_is_me? event is a convenient way to test if an event has anything to do with the current object.
Lines beginning with a pound sign (#) are comments and will not be parsed.
All mobiles will have
Inventory and
Equipment objects accessible via the
inventory and
equipment variables.
New objects may be created using
$manager.create_object:
scroll = $manager.create_object Scroll
inventory << scroll