COB Tutorial Lesson 3: The training weed The training weed is our first attempt to create a more complex type of object. This object will be dropped in Albia (the player can pick it up), and made available to Norns. They can eat a fruit, which will later grow back. The difference with this object is that it defines a script that says how the Norn will behave when eating it. This technique is used in many food objects, and so it's used here as well. Step 1: Planning I had considered making new sprites for this weed, but on second thought it's probably better to use a sprite already in the game. We'll use the sprites for the death cap mushroom. The first sprite in the file is a picture of the full weed. The second is a picture of the same weed with a mushroom plucked. I'll use class 2 15 65 for the object. Family 2, genus 15 is the category for weeds, and I'm pretty sure there's not a species of 65 floating around out there somewhere. 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 mush 2 0 3500 0 setv clas 34554112 setv attr 66 bhvr 0 1 mesg writ targ 8 edit You've already seen a typical installation script, so let's go through the unusual lines here. new: simp mush 2 0 3500 0 The new simple object created will use the mush.spr file its image, and it will only use two of the pictures in the file, starting with the first one (the 0 following the 2 stands for the first sprite in the file). setv clas 34554112 Sets the object's class to 2 15 65. setv attr 66 The user can pick up the object, but creatures can't. 67 is a normal value for items that creatures can pick up too. mesg writ targ 8 The object will be initialized by calling script #7. Now the object is set up. But what will we do with it? Step 3: The Scripts All right, here are the effects I want the training weed to have when eaten: Pain +255 Need for pleasure +255 Fear +255 Punishment +255 That ought to get their attention! Effects like that ought to frighten a Norn or Grendel enough never to eat weeds again. Or at least, they should. The chemicals we'll use are 17 (pain++), 18 (NFP++), 26 (fear++), and 50 (punishment). I got these from the chemicals.txt file. Now click in the "Scripts" box and then type the following in the edit box. scrp 2 15 65 1 stim writ from 200 255 0 0 17 255 18 255 26 255 50 255 snde chwl pose 1 tick 100 endm All right, let's go through the new commands. scrp 2 15 65 1 This introduces the activation script for this object. It is called when the creature tries to pull it. pose 1 Changes the picture to one without the fruit. tick 100 Prepares to call the timer routine (script 9). The timer routine will reset the weed to make it edible again. All right, now select "New Script" from the Scripts menu. We're going to add a new one. Once you've done that, click on the new script and enter this into the edit box: scrp 2 15 65 9 tick 0 pose 0 setv actv 0 endm Most of these are easy, but I'll go through them anyway. scrp 2 15 65 9 This is the timer script. tick 0 Disables future timer scripts. Without this command, the timer function would be called repeatedly. pose 0 Resets the weed's picture to its original state. setv actv 0 Makes it possible to pull the weed again. The actv flag was set to 1 automatically when script #1 was called; similarly, script #2 sets actv to 2, because it is the second activation function. One last script to go. This one's the really new one, the heart of our new object. scrp 2 15 65 17 drop impt 3 aim: 0 appr touc wait 4 pose 73 wait 5 mesg writ _it_ 0 pose 12 impt 0 wait 20 done endm Here's the rundown of that script: scrp 2 15 65 17 This script is called for the creature that activates the object. In this case, OWNR refers to the creature itself, not the object, which is _IT_. drop Tells the creature to drop what it's carrying. impt 3 Tells the creature that the actions ahead are mildly important. aim: 0 When the creature goes to activate the object, it will approach the right place to call activation function 1 (for this object, that's irrelevant; it doesn't have any buttons or anything). appr Approach the object. Continue macro once the approach is complete. touc Touch the object. wait 4 Pause before continuing. pose 73 Put the Norn/Grendel in pose 73. (I don't know what this is yet; just do it and find out later. I think it's the Norn stooping down.) wait 5 Another pause. mesg writ _it_ 0 Calls activation function 1 for the object. pose 12 I believe this is a standing pose. Who knows? impt 0 The following voluntary action is not important at all. wait 20 Pause before doing anything else. done The voluntary action has ended. All the rest is involuntary. endm The script is done. That's our last script, making three in all (not including the installation routine). If script #17 seems a bit of a headache, just ignore most of it and type it in verbatim. These external scripts use a lot of strange commands that aren't fully understood yet. Step 4: Looking Ahead We've now finished a training weed. This weed has an external script (#17) which tells creatures how to activate it. Once more poses are known, we can make creatures do more interesting things when using objects. Currently, one of the cooler scripts out there makes Norns drop-kick Albian Carrot Beetles. We can have a lot of fun with this kind of thing once more is known about poses.