Inject Your First Object
While one can use CAOS at the CAOS Command Line, this tutorial will jump into creating objects.
Part 1 - Teach Me CAOS!
Someone once said "Teach me how to do some CAOS stuff." I replied with:
new: simp 2 8 2 "caos stuff" 0 0 12
Undoubtedly, you'll have seen something really similar to this if you've ever looked at the .cos code in the bootstrap folder, or from another download somewhere. If you've not seen it, and you're looking a little confused, read through; it all makes sense!
What we're telling the game to do is make a new agent/object.
- NEW: - This tells the game, "yay, lets add something new", and the variables following this are what tells the game what exactly it's making.
- SIMP - This tells the game this is going to be a simple object, not a norn, not a compound object, not a vehicle, but something with one part that does stuff, like an apple, or a fish, or a simple machine.
- 2 8 2 : To be more precise, the part "2 8 2" tells the game exactly what it is. "2 8 2" is always an apple. These three numbers are known as the classifier, and in practice, you'll see that they are a good idea. For example:
- This can be summed up as:
- Family: living stuff
- Genus: fruits
- Species: apple
- Other examples might include:
The next part of 'new: simp 2 8 2 "caos stuff" 0 0 12' would be
- "caos stuff" - This is the part that tells the game where exactly it's loading the image (also called the sprite) from, i.e. the apple is "apple.s16" in the Creatures Images folder, or the cheese machine is "infinite_cheese_machine". This refers to the file "infinite_cheese_machine.s16" in the same folder.
And the last three numbers here refer to Image Count, First Image and Plane.
- Image count tells the game how many images in the sprite are used for this object, e.g. to animate it.
- First image tells the game where in the .s16 file (ie apple.s16) the first image this object uses is. For example, the corridor doors' images are all contained within the one file, doors.s16, and the nursery door uses sprites 98 to 119: 21 sprites for "image count" and 98 for "first image".
- Plane - Think of all the objects in the world as being a collage for a moment; Norns near the front, doors behind Norns, lift bars appearing in front of Norns, etc. This is due to the layering system Creatures uses. The higher the number (reaching a maximum of 9000), the closer it is to the camera. The background has a plane of 0, so anything else must be somewhere in between.
Part 2 - Let's Review
Let's review this line again:
new: simp 2 8 2 "caos stuff" 0 0 12
STOP! Please don't continue until you can explain more or less what all of this means, and how it relates to the games. I promise though, this is one of the hardest commands of the lot!
Part 3 - More CAOS
Some more CAOS:
Now you've injected your new CAOS stuff ... actually, please don't try to inject that. There's an "inject a cheese" tutorial coming up in just a minute. It will be functional :). Anyway, let's pretend you now have a new "CAOS stuff" object injected. Now you'll want to start giving it some properties!
For example, can you carry your new stuff? Can it be eaten?
- ATTR - The first of these usually is the ATTR. Attr, or "Attributes" is a number which you can give the object to tell the game what properties it has. Please look at the main ATTR article for a list of the attributes that you can give your objects. To give the object all of its attributes, we add up all the numbers for the properties we want. So if we want our "new stuff" to be carryable, mouseable, and activatable, we just add 1+2+4, to give 7...
Now we say:
And the game will calculate automatically that your new object is carryable, mouseable and activatable. Real clever, huh? You don't have to do the hard part.
BHVR - The way creatures can interact with the object is called the Behaviour, or BHVR. Please look at the main BHVR article for a list of the behaviours that you can give your object. Ok. Say we want creatures to be able to pick up and eat this object. We give it: 16 + 32, and get 48. So:
Once again, no math required, really... Well, it's all simple stuff unless you're trying to work out backwards what ATTR 198 is in your head :S (you can figure it out with the devthing easily).
And finally you'll want to give the object some physics...
- ELAS - This controls the elasticity (bouncy bounciness) of the object.. I.e. rubber ball versus rock.
- ACCG - acceleration due to gravity, or weight in other words... either way, this tells the game how fast it falls!
- FRIC - friction of the object.. I.e. if it has high friction it won't slide down a slope so fast.
- AERO - Aerodynamics... or how fast the object will fly if you pick it up and throw it.
- PERM - This is a little more complicated. It indicates how an object interacts with doors in a world - not the ones that creatures walk through, but the invisible ones that dictate how cellular automata and objects move through the world. For example, the Norn Terrarium walkways have doors that let some objects through, and the apples have a PERM of 60, so they will sometimes fall through and sometimes land on the walkway. Objects with a smaller permeability can go through more doors.
For our CAOS stuff, we might want to use:
ELAS 30 ACCG 5 AERO 5 FRIC 100 PERM 60
And finally, three more you'll need to know for the upcoming example:
- INST - Causes whatever script you've injected into the world to execute (run) instantly, i.e. the game will run this whole script before continuing at all. If it's a big script, there might be a considerable pause in the game. If not, then eh... who cares :)
- MVTO x , y - Move to the given X,Y coordinate. In C3, 'MVTO 700 750' would move the current object into the Norn Nursery area.
A note on scripts:
- Every object has an install script, and other scripts based on its attributes and behaviour. Was it clicked? Was it eaten? Was it picked up?
- The install script is run once to inject the object, while the other scripts are run as necessary, such as when your cheese is eaten, or every time the ball bounces.
Part 4 - Installing The Object
When you are installing a brand new object, such as one from the internet, chances are it will need to be clicked, carried, or activated in some way, and it will come with some scripts governing this. However, if, for example, we're injecting a cheese, the scripts are already there, so there's no point in making new ones. You'll see later.
For now, we're going to inject a cheese - here's some code:
inst new: simp 2 11 2 "infinite_cheese_machine" 2 44 8000 attr 195 bhvr 48 perm 64 elas 40 accg 10 aero 5 fric 20 mvto 700 700 endm
And there you have it, fresh cheese is injected straight into the game! Yay! Hey, aren't you proud? You should know more or less what that means now!
Run through this tutorial again. It's a little big, but you'll be glad you did, no doubt :)