A food dispenser

Introduction
Now we’ll move on to something a little more difficult. :) This tutorial will teach you how to create a dispenser (an object that injects another object each time you push it). This is a little harder than a simple food or drink as it contains a few extra scripts, but it’s not really that difficult (no CAOS is if you understand it properly). BTW I’m only explaining to commands I’ve not explained before as I’m assuming you’ve read the other tutorials in the series first.

Installation Script
inst new: simp hcvr 1 0 300 0 setv cls2 2 8 31501 setv attr 199 bhvr 1 1 slim edit endm

inst new: simp hcvr 1 0 300 0 The file this time is called hcvr (Helen’s Cheese VendoR) which is a lovely sprite made by Wafuru who runs the adventures in Nornsitting site (http://www.telesouth1.com/~ryouko/creatures/norn.html). Don’t forget to embed this into your cob!

setv cls2 2 8 31501 Same as always. This time the number is 2 (simple object) 8 (dispenser) 31501 (our special dispenser number for this particular dispenser)

setv attr 199 It’s 199 this time instead of 195 because we want this dispenser to do what the cheese and cordial did, but also be activate-able by the hand. The attr command is actually calculated by adding together those properties you’d like you object to show from a list of properties (I must put this list up on my site for download).

bhvr 1 1 It’s 1 1 rather than 0 64 because we want both the hand and Norns to be able to press it and we don’t want them to eat it.

slim edit endm

The dispenser push script

 * ominous music* Here’s the most important part for this cob. It looks quite a bit more challenging than the food and drink cobs from previous tutorials, but don’t be fooled. It only looks that way because it’s longer than the others.

scrp 2 8 31501 1 setv actv 0 snde vend stim writ from 0 255 0 0 45 150 0 0 0 0 0 0 setv va00 posb setv va01 posl subv va00 32 addv va01 43 inst new: simp cmac 2 25 1000 0 setv cls2 2 6 31508 setv attr 195 bhvr 0 64 slim mvto va01 va00 endm

scrp 2 8 31501 1 setv actv 0 This command deactivates the object once it has been clicked. This is an extremely useful command because it means the hand can click your object more than once. If you don’t put this in the hand will only be able to click the vendor once because there will be nothing else to tell the object to deactivate. It may seem a bit strange telling the dispenser to deactivate so early in the script, don’t worry. Creatures remembers that you want the object to be clicked again and then continues with the rest of the script.

snde vend Plays the vendor sound. I’m not quite sure if this comes as a default in the creatures 2 folder. I just took this sound from C1 (I’ll include it in the zip in case people don’t have it). You need to embed this file in your cob before you go any further so it will be on hand when other people inject your cobs. It’s always best to embed the extra files you use as you go as if you forget to at the end, this could crash who ever’s creatures when your cob is injected, or at the very least give a nasty error message.

stim writ from 0 255 0 0 45 150 0 0 0 0 0 0 This injects the Norn with some excitement (boredom decrease) as a sort of reward to pushing to dispenser.

setv va00 posb This command sets a variable (named va00) as the bottom coordinate of the cob. A variable is like an icecream container that can hold values until you need them. Just as you fill icecream containers with water when they are about to turn the water off in your street to do maintenance, when you want to grab a number to use later you put it in a variable. In creatures 2 you can use the names va00 - va99. We are finding out the bottom value of the cob so when we get the cheese to inject we can make it inject in the right spot where ever the dispenser is in Albia. What I mean by this is that instead of having the cheese inject to a set spot in Albia (say the coordinate 4000, 500), it will check where the vendor is positioned in Albia, do some calculations on that number (that’s in a minute, it’s only addition and subtraction though, so don’t worry) and inject the cheese in the right spot (the slot at the bottom of the dispenser where the cheese is supposed to come out). Before the variable must come a setv (which just means set variable) and after the variable you must put in the value you’d like to put into the variable. In this case we are filling the variable with the bottom-most coordinate of the cheese vendor in Albia.

setv va01 posl More of the same. This time we’re calling the variable va01 (to distinguish it from the other one) and this time we are filling it with the left most coordinate of the cheese vendor.

subv va00 32 Now we are subtracting 32 from va00 (our first variable). The subv command means subtract value. The value we want to be subtracted goes on the far right hand side, and the value we want it subtracted from goes in the middle. We’re subtracting 32 from the bottom coordinate of the vendor so we can position the cheese 32 pixels (it’s a measurement of dots it takes to make up a picture) up from the bottom of the picture. Often you need to play with this number for a while to get the product the dispenser is dispensing to come out at exactly the right spot.

addv va01 43 This time we are adding 43 to the variable va01. 42 is about the middle of the vendor. When the cheese is injected we want it to be injected in the middle of the vendor slot. To use this addv (add variable) command just put the two variables you’d liked added (in this case va01 - the far left coordinate of the vendor and 43) right of the addv command.

inst Recognise this? This is the install command from the install script. Surprisingly enough if you want to inject a new object using a dispenser you just add a install script into the push script of the vendor at the very end so that the cheese is installed. The rest of this is directly copied from the cheese script we did earlier.

new: simp cmac 2 25 1000 0 setv cls2 2 6 31508 setv attr 195 bhvr 0 64 slim mvto va01 va00 endm

Feel proud? You’ve just written the guts to your first vendor! Now we’ve just got to specify what happens when the cheese is eaten and then the cob is finished!

Cheese eat script
This is the exact same script from the cheese cob in tutorial one.

scrp 2 6 31508 12 snde chwp stim writ from 0 255 0 0 37 150 71 150 73 150 0 0 kill ownr endm

Removal script
Same as always except this one has two enum commands to get rid of the two different objects our cob brings into Albia.

inst enum 2 8 31501 kill targ next enum 2 6 31508 kill targ next scrx 2 8 31501 1 scrx 2 6 31508 12 endm

Conclusion
You’re getting quite good at cobs now! :) It took me ages and ages to figure out how to make a vendor (I’ve only actually ever made one vendor before this one that worked) and here you are already understanding *crosses her fingers* what makes a vendor work.

Acknowledgments
Thanks to Wafuru http://www.telesouth1.com/~ryouko/creatures/norn.html to making me such a nice vendor graphic and at such short notice too. It’s a very nice looking vendor that I’m sure any Norn would be happy to have in it’s home. :)

Thanks Sharon for making me get my act together and write another tutorial. :) I wrote this one at her request and because she has given me such encouragement after reading my other two

Thanks everyone else who has complimented me on this series so far!