Inject Your First Object

From Creatures Wikia

Jump to: navigation, search
Editnorn This article could be cleaned up to make it more readable.

This is the second CAOS tutorial Jennie wrote - posted with permission and partially rewritten and formatted for the Wiki.

Introduction

CAOS is more or less along the lines of a four letter command, followed by variables, etc...

But I'm going to start off somewhere a little unexpected and shoot right into some CAOS, based mainly on the idea that this approach has worked before.

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.
  • 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:
    • 2 - Tells the game it's in the family "living stuff"
    • 8 - Tells the game that the genus is a fruit.
    • 2 - Tells the game that the species is 2, specifically, an apple.
This can be summed up as:
    • Family: living stuff
    • Genus: fruits
    • Species: apple
Other examples might include:
    • A Norn: creature family (4), Norn genus (1), Species 1 (or 4 1 1).
    • A Grendel: creature family (4), Grendel genus (2), Species 2 (or 4 2 2).
    • A Rainbow Sharkling: living stuff family (2), fish genus (25), shark species (2) (or 2 25 2).

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 - Lets Review

Lets review:

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. It is actually much less confusing than it looks. If we want our "new stuff" to be carryable, mouseable, and activatable, we just add 1+2+4, to give 7...

Now we say:

ATTR 7
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:

BHVR 48
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 is used to govern the different levels, and different depths within the game and is why some apples will land on the wooden walkway, while some will fall all the way to the Norn Garden. More later.

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.
  • ENDM - Signals the end of the current script. :)

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 (Creatures3 Example) 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 :)

Next Part --> Intro to targ/enum/classifiers etc. Coming Soon.

Personal tools