creatures caves welcome, guest
downloads   gallery   dev   community   creatchi   forum   mycaves
ccsf | links | advice | chat | polls | resources | post

CAOS Chaos | Our Simple Object Un-Simplified!   Development   Rascii | 8/17/2012  log in to like post  1

updated6/30/2013
Learn about poses and 'do if' statements to make a simple food object that can be bitten multiple times.

Welcome back! If this is your first time reading one of my tutorials, I suggest reading the first issue, Requirements and Preparations, to get yourself ready. Now, let's move on to the actual tutorial!

In this issue, we'll learn how to make Charles the Cheese be bitten multiple times. We'll learn about poses of objects, and simple If...then...else statements. As a little extra, we'll also learn how to make things smelly!

Let's get started!
Since we'll be using the same Charles, we'll also re-use the scripts from the previous tutorial: First Simple Object: Cheese

So, what will we need to make our Charles have multiple bites? An image for each bite! Good thing all images are already present in the sprite file that came with the previous tutorial. In order to make Charles use these images, we'll have to change some values in his install script:

inst
new: simp 2 11 4645 "charles_cheese" 4 22 500
attr 195
bhvr 48
elas 10
accg 2
perm 100
seta va00 targ
enum 1 2 11
spas targ va00
doif ov00 = 0 and clac = 0
mesg writ targ 0
endi
next


We have changed that 1 to a 4! Do you remember what that number means? It tells the object how many sprites it can use, and the next number (22) says where this row of sprites starts. Now we'll be using 4 sprites, with 22 being the first one! If you have looked at the sprite, you'll see these are the bite images in chronological order.

Now we want Charles to actually use these new poses! Where would we add the script that makes the Agent change pose before it finally gets eaten? Correct! In the

Eating Script:

scrp 2 11 4645 12
snde "chwp"
stim writ from 79 1
kill ownr
endm


This was our original script. As soon as a creature eats Charles, the script gets executed and the Cheese 'kills' itself, dissapearing forever.

We'll have to tell Charles that if he isn't completely eaten then he should change to a new pose, or else he is now completely finished and should disappear . The text in bold is an example of how an if...then...else statement works. If certain conditions are met, a script will be executed. If not, another script might get executed, or the script just moves on.

What If?
Here's a quick example of the CAOS if-command, called 'doif':

doif <value> = <value>
do things
elif <value> = <value>
do other things
else
do other-other things
endi


<value> can be anything. It could be a number value, a string of text or even a specific object pointer (such as ownr or targ). The value then gets compared to another value, using one of the following symbols:

eq , = (equals to)
ne, <> (not equals to)
gt, > (greater than)
ge, >= (greater than or equal to)
lt, < (lesser than)
le, <= (lesser than or equal to)


You can string together multiple conditions using AND or OR. Conditions can be very creative. As long as the <value> part returns a comparable value, you'll be all set to go.
After this long and boring speech about doif-commands, let's actually use them to change out eating script! A newly created object starts at pose 0. With Charles, this is the uneaten pose. Pose 1, 2 and 3 are the ones with more bites taken out of poor Charles. So if Charles' pose isn't the last one (3), we'll increase his pose by 1, else, Charles is eaten and gone forever!

doif pose lt 3
snde "chwp"
stim writ from 79 1
setv va00 pose
addv va00 1
pose va00
else
snde "chwp"
stim writ from 79 1
kill ownr
endi


Make sure every if-block ends with an 'endi'. Not only does it look neat and tidy, it also tells the engine where the code stops.
If you've already tried this script on your agent and injected it, you'll notice that it now gets bitten 3 times before disappearance. But how does this work?
pose: 'pose' returns the which sprite, out of those defined in the install script, the agent is using. It starts counting from 0. The command returns a value and thus can be used in condition statement. As long as the pose is lesser than 3 it won't be killed. In theory, we could have left the stim and snde outside the block, since they'll get executed anyways.

Actually changing the pose is trickier, though. By getting the value of 'pose', putting it in a temporary variable, increasing it by 1 and then setting pose to the new value, it will be increased by one.

setv <variable> <value> will give a variable the value, so it can be manipulated and used for other commands. Variables come n 2 types: Object Variables (ovxx) and Local Variables (vaxx), where xx ranges from 00 to 99. Object variables store values for a specific object. They're often used to store things such as the age of a plant, or the energy a critter has. Object variables are always taken from the current object, which doesn't have to be the object that owns the script. Local variable store values througout the script only, independent of the current target. they're great for storing values for a short while.

So, what we actually did was setting va00 to the current pose, then increasing va00 by one (addv va00 1) and setting the new va00 back on the pose. Variables are hard to understand and explain., but you'll get used to them.

The completed script is as follows:

scrp 2 11 4645 12
doif pose lt 3
snde "chwp"
stim writ from 79 1
setv va00 pose
addv va00 1
pose va00
else
snde "chwp"
stim writ from 79 1
kill ownr
endi
endm


And that's all there's needed to make your food item multi-bite. :D

Hey? What smells?
Norns in C3 and DS can use their sense of smell to locate friends, enemies, home and even food! But how would we make our Cheese smelly? With the emit command!

emit <type> <amount>


This line tells the current object to start emitting this scent, or CA. CA's can be things like Light, Heat, Moisture, Nutrients or various kinds of smell. They travel from room to room depending on the room properties. Creatures and some agents use them to navigate, while some agents, such as plants, use them to know if they're growing in warm, moist soil.

You can find a list of CA's here.

The amount ranges from 0 to 1, and anything in between. This means you'll have to decimal numbers, such as 0.314. Put the 'emit' command in the install script of the cheese. Right after 'bhvr' would be fine. Give it a smell of 0.3, which should be more than enough.

Tadaa!
There you go! Some good old smelly multi-bite cheese! Now you can try all sorts of things with the stuff you've learned! How about making some fruit? Or a cake that takes a gazillion bites before it's fully eaten?
A good exercise would be making some cheese that emits less smell when it's eaten more. ;)

Well, that's it for now! See you next time!

CAOS Chaos is a set of agent tutorials originally written by AquaShee for Edash's Creatures. The articles are currently archived here for the benefit of the Creatures Community.

 


downloads
cobs
adoptions
creaturelink
metarooms
breeds
 
gallery
art
wallpaper
screenshots
graphics
promos
sprites
dev
hack shack
script reservations
dev resources
active projects
dev forum
 
community
links
advice
chat
polls
resources
creatchi
 
forum
bookmarks
general
news
help
development
strangeo
survivor
mycaves
log in
register
lost pw
0 online
creatures caves is your #1 resource for the creatures artificial life game series: creatures, creatures 2, creatures 3, docking station, and the upcoming creatures family.

contact    help    privacy policy    terms & conditions    rules    donate    wiki