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

CAOS Chaos | First Simple Object: Cheese   Development   Rascii | 8/17/2012  log in to like post  6

updated5/1/2013
Learn how to code a very simple food object.

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 code a very simple food object. We'll learn about injecting agents into your world, giving them properties and images and adding scripts to them so they respond to things happening to them.

The Beginning:
Before you start coding, you will need some images to represent your agent in the world of Creatures. Charles the Cheese was kind enough to lend us his amazing profile (made by Moe, thanks Moe!) which we'll use in this and other tutorials. Download Charles the Cheese and extract his images into a new folder in your projects folder. Make a copy of the .c16 file and put it in your C3 or DS images folder. If you have both games, the C3 folder would be best.

If you would open the image file with the Sprite Builder, you would see a bunch of images of a walking cheese with feet. This is the complete animation needed to make the cheese walk and get eaten. We'll only use a single image of the file in this tutorial, but the others will be used eventually. :)

The Installation Script:
We are now ready to start writing our code. Start C3 or DS and open the CAOS Tool. You'll be presented with an empty window with a few familiar buttons at the top. Click the first button to start creating your first .cos file.

.cos files are almost identical to .txt files created by Notepad, except that they contain CAOS code and are used by creatures.

Now, type or copy the following code into the window:

inst
new: simp 2 11 4645 "charles_cheese" 1 22 500
attr 195
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


Now you have written your first agent install script! You can inject the script into your game by clicking on the icon that looks like a sheet of paper with some blue and purple lines on them.
Your inventory should open with a cheese inside!

But what does all this text mean? Let's take a look at what we wrote:

inst


This little bit will make the engine execute the next row of commands in a single tick until it reaches a command that slows it down or the row of instructions ends. Normally, the engine executes only one command per tick.

new: simp 2 11 4645 "charles_cheese" 1 22 500


Remember that this has to be put on a single line. The brower may accidentally cut lines off, so be careful with that when copying code from these tutorials.
This line is what actually creates the agent. 'new: simp' means we are going to create a simple kind of agent.

The following 3 numbers are called the Classifier and are very important, they are the family, genus and species (in that order) of the agent. They make your agent unique from other agents and are used as a reference for event scripts and other agents. Norn also use them to keep agents apart.

Let's take a look at what those numbers mean:
- Family: This number defines the most basic type of object: 1 = System or Background (invisible to Norns), 2-3 = Regular objects (seen by norns), 4 = Creatures. Those behaviours are not hardcoded, but recoding them would mean recoding everything, so we won't do that.

- Genus: This is more specific. For Family 1, this number won't really matter. In Family 2 and 3, this number defines what the object is called by Norns, such as food (2 11), plants (2 4) and lifts (3 1). In Family 4, it defines the species of Creature (1 to 4 = Norn to Geat).
You can use the Classifier List to find out about the different object types.

- Species: This is a very important number. together with the Family and Genus, it gives your object an unique identifier. It's what makes your Cheese object different from other objects in the world. You'll have to try and reserve a small range of species numbers if you want to make your own batch of agents. I recommend you look around on Forums and try to find out what a good range couild be. For now, you can use the numbers I provide in my tutorials. My personal range goes from 4600 to 4650.

Ok, that was confusing. Don't worry about it too much :) It took me a while before I understood this line of code completely myself.

"charles_cheese" 1 22 500


You'll probably recognize that first part. It's the name of the sprite file the agent uses! Make sure you put in inside quotes and don't include the extension.
The next 2 numbers are kinda confusing, bet very handy. They tell the game what sprites of the file they should use. The first number is the total number of sprites to use, and the second number is where this row starts. We are using a single image, which is located at position 22 withing the file. Take a look with the sprite builder. You'll notice that the sprites are counted starting with 0.

The last number is the plane of the agent. This tells the game how close the agent is to the foreground or background. The higher this number, the closer the agent will be to the screen and it'll sit in front of other objects. If this number is really low, it will appear behind all other objects. If 2 objects are on the same plane, the one that was picked up or changed plane last will be in front.
Norns have a variable plane that can be anything between..umm..I actually have no idea what plane Norns often occupy...I do know that a plane of 5000 will be in front of Norns, and 500 is behind them. :)

attr 195


The attr, or attribute number of an object is very important. It holds vital information such as gravity, floating relative to the screen, being clickable,... Look up the attributes flags in your Categorical Gude to find out what values they are. To select multiple values, you have to add them up so you get an unique number that corresponds with only one possible combination of attributes.

Our Cheese has attr 195, which is Carryable+Mousable+Suffer collisions+Suffer Physics. This mean our object will fall to the floor, bump against boundaries and can be picked up by the mouse and other things.

elas 10
accg 2
perm 100


These 3 command set other values for the agent.
'elas' sets the elasticity of the object. After bumping into something, it will keep only 10% of it's original speed.

'accg' is the weight of the object. Setting this value negative will make the object fall upwards!

'perm' will set the boundaries the object will fall through. A perm of 100 means that the object won't fall through any floor. Norns also have a perm of 100. Seeds should have a lower perm, so they'll fall through platforms and stuff.

There are other values like this you can give to objects. Look them up in your Categorical guide. If you don't need some of the values, you can simply leave them untouched. :)

enum 1 2 11
spas targ va00
doif ov00 = 0 and clac = 0
mesg writ targ 0
endi
next


This piece of code is a lot more advanced. It puts the created object, which hasn't been moved into the world yet, into your inventory. As far as I know, this is the very first object that gets put in your inventory when it's created. :) Basically the little script goes through all Inventory objects (should be only 1), moves the agent in there and sends a message to the Inventory to open itself when it isn't already.

The Eating script:
Great! If you're still with me so far, we now have made a small object that gets put in the game and does..well...nothing at all. tyou can throw it around a bit, and your Norns might try to eat it, but they won't be able to. Now it's time to make the Cheese react to a Norn's bite.

Add the following lines of code beneath the injection script:

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


This is called a 'script' or 'event script'.
'scrp' defines the start of a new script. The Classifier number says which object the script iis applied to, and the last number (12 in this case) tell you what event this script is linked to. Event 12 is 'eaten by Norn'.

To make the script actually execute when a Norn tries to eat the agent, you have to tell the agent it should respond to eating events. Add the following code in the Install script:

bhvr 48


Fit it somehwere between the 'elas' or 'attr' commands.
'bhvr' or Behaviour works just like the 'attr' command, but it defines what actions a Norn can use on that agent. bhvr 48 enables Norns to pick up and/or eat the agent.

Now when you inject the agent, it should be edible by Norns. You'll probably have loads of cheeses lying around that haven't been made edible since they were already injected. Don't worry, we'll learn how to remove the agents we made later. First, let us look at the workings of the eat script.

snde "chwp"


This will play the .wav file called "chwp", making a chompy sound. Sound files are always in .wav format and go in the Sound folder. For some reason, they have to be 4 characters long, made out of letters, numbers and/or underscores.

stim writ from 79 1


Tricky command, but you'll use it often in agents that interact with Norns. In English, it would mean: send stimuli 79 with an importance of 1 to the agent the event was triggered by.
In this case, the Norn that tried to eat the Cheese, would get stimuli 79 (eaten food) and receive the nutrients defined in it's genome. The importance tells you how strong this stimuli is. 1 is the default value. A strength of 2 would send a stimuli twice as strong, so the Norn would learn more from eating the food, but will also gain more nutrients. A strength of 0 will send a regular amount of chemicals, but no learning at all.

kill ownr


This command sounds dangerous, and it can be. it removes the 'ownr' (owner) of the script from the world. This means the Cheese. This way, the cheese will be gone after it gets eaten. If you would leave this part out, the Norn could take infinite bites out of a single cheese!

endm


This simply ends the current script.

Now, what do we have so far?

inst
new: simp 2 11 4645 "charles_cheese" 1 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

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



Adding a Remove Script:
This was the whole Cheese script so far. But what if we want to remove those cheeses?

Add the following lines of code to the end of the .cos file:

rscr
enum 2 11 4645
kill targ
next
scrx 2 11 4645 12


'rscr' starts the Remove script. This script gets executed when you remove the agent with the CAOS tool (paper with red lines on it) or the Creator.
'enum 2 11 4645' cycles through all agents with that classifier, then kills the target and moves to the 'next' one. You can now remove your cheeses and inject some new ones if you like.
'scrx 2 11 4645' removes the script from the script database, also called the 'scriptorium'. This way, other agents can't accidentally use this script.

Wrapping things up:
Now that our .cos file is complete, we should wrap up our agent together with it's images so we have a handy .agent file we can give to our friend and relatives, and inject with the Creator Machine.
Open up EasyPRAY, and follow the instruction to compile your .cos file into a real agetnt. Basically, you'll have to select some option, open your CAOS file and enter information about your agent. It isn't too hard, but very lengthy to explain. I'm sure you'll figure it out.

Whew, that was quite a bit of information we've got here! I suggest you read everything through and make sure you understand things. Read a bit in the CAOS Categorical Guide and look at some of the more interesting commands, fiddle a bit with your cheese, etc. Don't hestitate to ask me questions through PM!

Until next time, in AquaShee's Caos Chaos.

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.

 
 
cyborg | 10/2/2019  log in to like post

If you have an error like:

"Install script caused an error or exception:
Tried to set BHVR 48 when the agent doesn't have one of the appropriate scripts"

Inject the remove script, then inject both the install and event scripts at the same time.
 
Octopouf | 6/29/2015  log in to like post

I'm having problems. When I introduce the bhvr to the rest of the code, it fails to import into the game. I get this message:

Install script caused an error or exception:
Tried to set BHVR 48 when the agent doesn't have one of the appropriate scripts... " 1 22 500 attr 195 {@}bhvr 48 elas 10 accg 2 perm 10 ...

I double checked all codes on the Beginner Document and CAOS Documentation, it's all correct. Any clues?
 
NornBreeder | 9/30/2014  log in to like post  5

This is amazing! I may finally be able to make something for a game I've played for so long


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