COB Tutorial Lesson 1: A simple food object I've heard a lot of people say they don't know where to start with COB programming. Well, I don't blame you. It's kind of confusing, isn't it? Well, I've decided to start a tutorial series to help. This lesson: Making a simple food object. I don't mean putting a carrot into the world; I mean making a new type of food from scratch. Step 1: Planning I think I'm going to make a variation on cheese. That way, I'll have graphics already available. Cheese is class 2 6 1. Since I don't want to alter the behavior of existing cheese, I'll have to create an entirely new class of object. Family 2 and Genus 6 are a must; that's the same for all food. I'll make a new species. Let's say this is species 65. I don't think there's another object out with class 2 6 65. It is very important to make the class unique for each object. If you install a script over an existing script, you'll change the behavior of existing objects. The sprites I'll use are in the food.spr file. The cheese sprites are 3-5 in the file. Step 2: Installation Okay, now I'm ready to start CobCom and edit the object. CobCom starts up with two list boxes displaying "". One of them is for scripts; another is for the installation routine, in the box marked "Installation Scripts" ("Imports" in CobCom 1.02 or earlier). Click on that. Now, "" appears in the window beneath. This is the editing box, where you'll type in the installation script. Click in the edit box. Go ahead and delete the line that appears there. Now type in the following: inst new: simp food 3 3 3500 0 setv clas 33964288 setv attr 67 bhvr 0 1 edit Now, let's examine each line one by one. inst This command tells the object injector to execute the rest of this script before updating anything in the game. This is necessary when installing new objects, like we're doing here. new: simp food 3 3 3500 0 This creates a new simple object with the following properties: food The sprite file to use for the new object. 3 The number of images belonging to the new object. 3 The index of the first sprite used by the new object. 3500 The "plane" of the object. This tells the game how far forward or back it is. 0 Tells whether the image is cloned. I don't understand it either; just put in 0. setv clas 33964288 This is the object's class. It corresponds to the hexadecimal number 02064100, which is basically 2 6 65 0 when broken down into separate bytes. COE and CobCom can calculate this number like this: 2×256×256×256 + 6×256×256 + 65×256 setv attr 67 The attr flag defines some of the behavior of the object. 67 is a combination of 1 (creatures can pick it up), 2 (you can pick it up), and 64 (constrained to the boundaries of the room). Just leave this alone for now; later, you can read the possible values in the macro.rtf file. bhvr 0 1 This is another command you should ignore for now. It suffices to say that the 0 stands for what the user can do to activate the object--in this case, nothing. The 1 is what creatures can do; they can call the act1 activation function (script #1). edit This attaches the object to the hand, so you can place it in Albia. This command is basically used to pick things up. Okay, now we've built an object installation script. Fine, but the object isn't going to do anything unless we tell it to. So, let's decide what to tell it. Step 3: The Activation Script Well, what do we want this new cheese to do? I think I'll make it do this: Hunger -250 Starch +50 Glucose +100 Anger -20 Kind of a strange batch of effects, isn't it? This is less nutritious than ordinary cheese, but it satisfies hunger just as well and it's sweeter. It also has a mild calming effect. The chemicals we'll use are 35 (hunger--), 57 (starch), 58 (glucose), and 44 (anger--). I got these from the chemicals.txt file. All right, now click in the "Scripts" box and then type the following in the edit box. scrp 2 6 65 1 snde chwp stim writ from 10 255 0 0 35 250 57 50 58 100 44 20 kill ownr endm All right, let's go through it. scrp 2 6 65 1 This introduces the activation script for this object. It is called when the creature tries to pull it. snde chwp Makes a chewing sound. stim writ from 10 255 0 0 35 250 57 50 58 100 44 20 Okay, this one will take a little doing. stim The heart of the command. This tells the game that you will be describing a specific stimulus (hence all the numbers). writ from "writ" is used in stimulus commands to tell them to stimulate a specific object. "from" tells it to stimulate the Norn/Grendel who activated the object. 10 This has something to do with how important the stimulus is. If you want the Norn to really pay attention, increase this number. 255 0 The sensory neuron to adjust and the amount of adjustment. 255 means no neuron is being adjusted. 0 A bit record of features. I have no idea what this means, but nobody uses it anyway. 35 250 57 50 58 100 44 20 This is a list of all the chemicals we're using to stimulate the Norn. As you can see, they're listed by pairs: chemical, then amount. If the chemical is set to 0, it is not used. NOTE: You must list exactly four pairs of numbers here. If you are only going to use one or two, set the others each to "0 0". If you want to use more, add another stim command. kill ownr Destroys the object. It's been eaten. Its work is done. endm Ends the macro. This is probably redundant, but it's good for safety's sake. That's it. Now enter a name in the name box and save the object. Step 4: Moving On Congratulations, you've just created a cheese variant. This doesn't do anything fancy, like change poses when it's picked up. Many food objects use a special script that causes creatures to take more interest in an object once they drop it. But by examining other COB files you can at least get some idea of how that works. Something else you can do is create completely new sprites for this object. For example, you could depict a cheese wheel instead of a wedge. That would let users tell the difference from regular cheese.