|
The best way to learn any language is by example. In this case, that's especially true. Examining other COBs is a good way to do this, but if you want to create an object from scratch, step by step, this is the place to start.
Intro: The basics of the language.
First of all, there are two types of code used by objects: Scripts and installation scripts. Most objects have one installation script and several regular scripts. This is not necessarily true for all objects, however. An object can have no installation script, and merely install scripts to run later; or, it can have no scripts besides the installation script.
A common type of object with only an installation script is one that inserts a copy of an existing object (like cheese or a ball) into Albia. The scripts that run the object are already installed, so there is no need to add new ones. The installation script creates an object and places it within the world, then quits.
Installation scripts always begin with inst, without exception. This tells the game to execute the script in a single timer tick. inst can be used in other scripts to do the same thing, but it is required here.
Other scripts begin either with the scrp command, which installs them into the scriptorium, or the scrx command, which removes a script. For example, scrp 2 6 1 1 installs script #1 for an object of family 2, genus 6, species 1. (That object, by the way, is a piece of cheese. Script #1 is one of the activation functions.) These commands, too, can be used within a script, although the practice is uncommon.
The number of a script is the event that triggers it. To see a full list of events, read scriptnumbers.txt on the Reference page.
An object's class is its family, genus, and species. This determines what creatures will call it, and a bit of how it behaves. Most objects are simple objects, in family 2. Compound objects (including vehicles, lifts, the computer, etc.) are family 3. Creatures are in family 4.
The genus is also important. Family 2, genus 6 is the category for all food objects. Genus 7 is drink objects. 13 is toys, 14 is big toys; 4 is plants, 15 is weeds. You can observe some of the class categories by looking up a typical object in the list of implementation codes (also available on the Reference page).
Example: If you don't know what class 2 12 x is (family 2, genus 12), open the list of implementation codes and search for any objects with family 2, genus 12. You should find either the shower or the clock; those are both in the class of soothing objects, which Norns may call "shower" or "clock" or something similar. If you want to create a soothing object, think of a species number that (most likely) no other objects are using.
The reason class must be unique is that Creatures will try to run scripts for your object. If you install a new script with the same class as an existing object, the old object's scripts will be dumped in favor of the new one. If you use scrp 2 6 1 1, for example, you'll change the behavior of all cheese objects in the world. New cheese won't behave properly, since they don't install any scripts.
You might be tempted to use duplicate classes for your own objects, if you think no one will be using more than one kind at a time, but that's a really, really bad idea.
To set an object's class, you must use the
setv clas
For simple objects (family 2), you must also supply a set of attributes using the ATTR flag. A list of values for this flag is available in the macro language documentation. Also, you should set the object's response to clicks or creature activations using the BHVR command.
In the examples, I use CobCom to code the scripts. In CobCom, you can enter line breaks and the program will remember to use commas to separate the commands when you're done.
Enough blather. Read the first lesson, already.