Welcome to the Creatures Wiki! Log in and join the community.

Toy tutorial 1

From Creatures Wiki
Revision as of 00:23, 26 January 2020 by ScoobyGambit (talk | contribs) (Created page with "==Introduction== Well now that you’ve mastered food cobs, lets try something completely different and make a new toy for your Norns to play with. In this tutorial, we will b...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Introduction

Well now that you’ve mastered food cobs, lets try something completely different and make a new toy for your Norns to play with. In this tutorial, we will build a replica of the toy truck cob I’ve made for download. I’m assuming you’ve read my other tutorials so I’ll only explain the new commands.

Installation script

inst
new: simp hcar 2 0 3500 0
setv cls2 2 13 31509
setv attr 199
bhvr 1 1
slim
edit
endm

Nothing new here at all. It’s the same as any other cob installation script (most similar in fact to the cheese vendor that we did last tutorial) except this time the genus number in the classifier is set to 13 (which is the genus number for toy.

Activate script

scrp 2 13 31509 1
setv actv 0
snde hcr1
stim writ from 0 255 0 0 45 255 0 0 0 0 0 0
rndv var0 0 1
pose var0
doif pose eq 0
reps 10
setv velx 6
wait 1
repe
else
doif pose eq 1
reps 10
setv velx -6
wait 1
repe
endi
endi
setv velx 0
endm
scrp 2 13 31509 1
snde hcr1
stim writ from 0 255 0 0 45 150 0 0 0 0 0 0

This time we are injecting the Norn with boredom decrease (excitement).

rndv va00 0 1

Remember the variables from the vendor cob? This command fills the variable with a random number between 0 and 1. RNDV means random value, va00 is the variable we’d like to contain the random number and 0 and 1 are the range the random number can be in. The random value is a very useful command because the number will not be the same each time you activate the cob, so it can be used to make the cob do different things each time you press it. In this case the random number will be used to make the car go right fifty percent of the time and left the other fifty percent of the time.

pose va00

We are changing the pose of the object. The pose is just another way of saying picture. If you look at the sprite file for this object you will notice that there are two pictures in there. If pose is zero picture zero (the first in the file) will show. If pose is equal to one picture one will show (the second picture in the file. va00 is our variable from the last command. In this variable we inserted a random number (either one or zero). Instead of setting the pose as a definite number (ie. pose 0) in this script we are setting it to be whatever the random number happened to be, which we stored in the variable va00. So pose va00 in plain English would read “set the picture of the toy car to whatever the random value set above and stored in variable va00 is”.

doif pose eq 0

The doif command is a very useful one. This command can contain script which is to be executed (run by Creatures) only if the statement following it is true. In this command the code between the end of the doif statement and the else or endi commands will only be run if the pose of the object is equal to zero. A doif command is not finished until you have an endi code. In plain English this command would read “do the next piece of code only if the first picture in the sprite file (the picture of the car facing left) is showing”

reps 10

Means repeat the everything between reps and repe 5 times. reps is short for repeat script and repe is short for end of repeat command.

setv velx 6

Ah! This is the bit that actually makes the cob move! This is an extremely cool command and can be used in any type of cob where you want to move you cob from one place to another without “teleporting” it. Setv means set variable. Velx means the X velocity or the speed and direction of the object along the X-axis (from left to right rather than up and down). 6 is the speed the object is moving. So this object will now move in the left direction with a speed of six until we tell it to stop.

wait 1

Just what it says. This command tells Creatures to wait for one second before going on to the next command.

repe

End of repeat script. Tells Creatures that it doesn’t have to repeat anything any more.

else

Here’s a continuation of our doif command. The code between here and the endi command is what we would like the cob to do if the doif statement is not true. (If the pose of the object is not zero).

doif pose eq 1

Here’s another doif command. You can have them embedded inside each other as long as the second doif is after the else command of the first. This is handy especially if you create a cob where the random value isn’t between 1 and 0, but 1 and 3 and you’d like something different to happen if the random number is 1, something else when the random number is two and something different again if the random number is three. This time the code between the doif and the endi will only execute if the pose of the object is one (the picture of the car facing right).

reps 10
setv velx -6

Very similar to the last velx command only this time because the number is -6 instead of 6 the car will travel left instead of right.

wait 1
repe
endi

Endi is very similar to endm except endi signifies the end of the doif statement rather than the end of the script.

endi

Another endi because we used two doif statements.

setv velx 0

Sets the speed of the car back to zero (so the car will stop moving).

endm

Well that certainty wasn’t too hard. It’s a lot of new commands to learn, but these commands are invaluable when you want to script things later. They are what more complex cobs are structured on.

Drop Script

scrp 2 13 31509 6
snde drop
endm

Remover script

inst
enum 2 13 31509
kill targ
next
scrx 2 13 31509 1
scrx 2 13 31509 6
endm

Conclusion

Finished your first toy cob. :) Toys are some of the most fun cobs to make (well in my opinion anyway). The trick with these is to design them just as much for the hand to play with as for the Norns to play with. :) Also flashy graphics and neat sounds go over well too.