Cob Tutorial 9

Introduction
This time we’ll make a critter cob. This critter is a snake that is injected with the mystic forest cob. I’ve had a few requests for this and I think you’re just about ready for it. A critter cob is a bit harder than most of the others we’ve done so far, because some the concepts used in a critter are different from those used in most other objects. A critter must do stuff continually without imput from the norns or hand, while for all the other objects we’ve created so far we have only needed to make things happen when it is interacted with by a creature or the hand. This isn’t too hard to do, it just moves the focus away from the push or eat scripts, that have been the longest scripts in previous cobs, and towards the timer script.

Installation Script
inst new: simp snke 16 0 3500 0 setv cls2 2 20 31501 setv attr 193 bhvr 0 0 slim edit tick 1 endm

inst new: simp snke 16 0 3500 0 setv cls2 2 20 31501 The genus of a critter is 20. Besides that this line is the same as in all the other objects we’ve done.

setv attr 193 We want the hand and norn to be able to pick up the snake, and we want the snake to fall and collide with things so we’ll set the attributes of the object to 193. Each object can be assigned various attributes. Each of these attributes is assigned a number. The attribute number set here is found by adding together the number of each attribute you want the object to possess. In this object we want the hand to be able to pick up the snake (1), suffer collisions (64) and suffer gravity (128). To get the attr number we added these things together (1 + 64 + 128 = 193).

bhvr 0 0 We do not want the hand or the norns to be able to activate the snake. It will be for decoration only.

slim edit tick 1 Call the timer script as soon as the snake enters Albia.

endm

Timer Script
scrp 2 20 31501 9 rndv va00 0 1 doif va00 eq 0 reps 7 anim[01234567] setv velx 6 over repe else doif va00 eq 1 base 8 reps 7 anim[01234567] setv velx -6 over repe base 0 endi endi tick 1 endm

scrp 2 20 31501 9 This is a timer script so the script number is 9.

rndv va00 0 1 We want the snake to move left sometimes and right sometimes. A random value is a good way to do this. It will move left about 50% of the time and right about 50% of the time. This is also good because it doesn’t move right ever second time and left every second time, it is random so the snake does not seem to be moving uniformly.

doif va00 eq 0 reps 7 We want the repeat the next bit of script 7 times.

anim[01234567] Animation of the snake moving left

setv velx 6 The snake moves left

over repe else doif va00 eq 1 base 8 reps 7 anim[01234567] Animation of the snake moving right

setv velx -6 The snake moves right

over repe base 0 endi endi tick 1 We want the snake to move constantly. This command tells the timer script to execute again in one tick. If we ask the timer script to repeat again at the end of the timer script itself, it will create an infinite loop and the snake will keep moving left and right until the cob is uninstalled or the world ends. (Heaven forbid anyone should ever want to remove poor snakey).

endm

The timer script is the basis for all critters and plants (or any “living” cob). Congratulations. You’ve just done the hard bit of a critter cob. Now on to the remover and you can test out snakey in your world.

Removal Script
inst enum 2 20 31501 kill targ next scrx 2 20 31501 9 endm

Just a straight forward removal script. Nothing new here.

Conclusion
There, a critter cob. Pretty easy, hey? The hardest part of a critter cob is finding some animated graphics to make it look convincing as it moves around. Another milestone in your cobbing career. Ah, I remember my first critter *eyes unfocus and smile of reminiscence appears on Helen’s face* twas a butterfly with beautiful pictures made for me by a guy called Malveka. Took me months to work up my courage to try a critter.

Acknowledgements
Sprites for snakey by Christian - BuddhaMage@aol.com