creatures caves
welcome, guest 

downloads   gallery   dev   community   creatchi   forum   mycaves
ccsf | links | advice | chat | polls | resources | post
 

  

Creating a Metaroom - Part 5: Agents   Development   Malkin | 5/23/2013  log in to like post

updated5/23/2013
Part 5 of 7 from the Creation of a Metaroom: From Inception to Release series by Liam, a basic land critter which uses subroutines.

Part 5 of 7 from the Creation of a Metaroom: From Inception to Release series of articles.

Agents are what make a room truly interesting, unique, and interactive. Without them, a room is simply a pretty picture, with no real purpose or function. There are generally 2 main purposes for agents; for norns, ettins and grendels to interact with, and for the player to interact with (or simply watch).

Introduction

Agents are what make a room truly interesting, unique, and interactive. Without them, a room is simply a pretty picture, with no real purpose or function. There are generally 2 main purposes for agents; for norns, ettins and grendels to interact with, and for the player to interact with (or simply watch).

Decide which function your room serves ? is it an environment for norns, ettins and grendels, or mainly for the enjoyment or use of the player? The agents your room will contain will change drastically according to which of these you choose.

Generally, the basics needed to support norn life in a room are:

? Food sources
o Protein (critters)
o Fat (often fruit)
o Starch (seeds, vegetables)
? Cellular Automata (covered in Part 6)
? A way to transport norns in and out of the room (a door or teleporter)
? Toys for entertainment


For a room mainly dedicated to the player, things such as food sources and toys are less important ? the Infirmary is a perfect example of a player-oriented room. There are no food sources or toys to entertain norns, ettins or grendels with, just a utilitarian interface for the player.

Short Agent Guides, tutorials and Walkthroughs for agent making:

o Lift Script (Wiki)
o Simple Plant (Wiki)
o Simple Land Critter (Below)

An Introduction to Subroutines

Subroutines are some of the most useful things when coding critters, plants, weather? well, almost anything really. Basically, a subroutine is a section of script which is executed (run through) when the user specifies. A subroutine is placed in the timer script, though I believe the ?execute this subroutine? command (gsub) can be used in any script.

The syntax is as follows:

*This will execute the subroutine
gsub our_test_subroutine

*This is the subroutine
subr our_test_subroutine

accg 0

retn



This will make any agent with that code in its timer script float. Simple, no?




Basic Land Critter Tutorial

Before you take a look at any of these tutorials, I must stress that you need to have at least a basic knowledge of CAOS to understand what is going on here. I?ll explain the more complex parts, but I?ll assume you know commands such as new: simp and attr 199.

For some more basic tutorials, I?d suggest the Creatures Development Network (the CDN), caos chaos.

Okay! For this tutorial, we will be using the Gerana from the Grendel Hideout, coded by myself. It is a small slug-like creature which moves relatively slowly, and the specifications I was given were simply that it needed to move around, so that is mainly what will be covered in this tutorial - more complex scripts can be added later, but to start with all we want is a critter which moves.

To start with, lets take a look at the variables we will be using in this tutorial.

*ov10 direction (1 is left, 2 is right)
*ov11 direction of wall the critter is approaching (if applicable)
*ov40 (random) how many 'walks' in a particular direction the critter does

These are fairly self-explanatory, I?d think. Remember, ALWAYS comment your scripts in detail, so that if you ever need to go back you have no fear of forgetting what happens in the script.

If you don?t understand the variables yet, you will in a moment, don?t worry!

Firstly, we want to create the Gerana.

*Inject the Gerana and set properties
new: simp 2 15 21021 "b1-snett" 42 18 2000
attr 194
elas .1
accg 1
perm 100
base 0
*Set basic variables all to 0
setv ov40 0
setv ov10 0
setv ov11 0

*Move into the Grendel Hideout (change these coordinates!)
mvsf rand 9900 10500 340
tick 1


Okay! Now that that?s done, we can move onto the real scripting - the Timer Script! The timer script is where all the actual working of the critter goes. As with zareb?s simple plant script on the Creatures Wiki, its easiest to work with critters through subroutines - it helps split up the timer script and make it more understandable.

For this critter, it will simply stay in your world forever until you remove it- we won?t be giving it a dying or reproduction script. If you want critters in your room, they don?t actually need to reproduce, but it IS cool if they do.

So, let?s take a look at the Timer script.

scrp 2 15 21021 9

*This is where any subroutines you want to happen go.
*For now, this is just the movement subroutine!
gsub walk

*The walking subroutine! Yay.
subr walk

*Set the amount of 'walks' to a random number between 3 and 9
*The more walks you want, the higher the last number
setv ov40 rand 3 9

*Set the direction randomly right or left
setv ov10 rand 1 -1

wait rand 1 10

*If there is a wall to the right, set ov11 to 1
doif obst rght lt 5
setv ov11 1

*If there is a wall to the left, set ov11 to 2
elif obst left lt 5
setv ov11 2

*Otherwise, just set ov11 to zero (so it has no effect)
else
setv ov11 0
endi

*If the critter is not being carried and is not falling
doif carr eq null and fall = 0



*Checks for walls (using the variables we set earlier)
*If there is a wall to the right, go left
doif ov11 = 1
gsub left
endi

*If there is a wall to the left, go right
doif ov11 = 2
gsub right
endi

*Checks if the critter is going right
*If so, go to the 'right' subroutine
doif ov10 = 1
gsub right
endi

*Checks if the critter is going left
*If so, go to the 'left' subroutine
doif ov10 = -1
gsub left
endi

*Otherwise, stop.
else
stop
endi



Having any trouble following yet? I hope not! As I mentioned earlier... the key to understanding scripting is lots of comments. Let?s take a look at the walking right and left subroutines. Don?t worry; these are a LOT easier to understand!


*The going right subroutine
subr right

*Repeat for ov40 times (randomly between 1 & 6)
*The animation and movement is split up,
*Which hopefully makes it look more natural.
reps ov40
anim [8 9]
velo 1 -1
over
anim [10 11]
velo 1 -1
over
anim [12 13]
velo 1 -1
over
anim [14 15]
velo 1 -1
over
repe
retn





*The going left subroutine
subr left

*Repeat for ov40 times (randomly between 1 & 6)
reps ov40
anim [0 1]
velo -1 -1
over
anim [2 3]
velo -1 -1
over
anim [4 5]
velo -1 -1
over
anim [6 7]
velo -1 -1
over
repe
retn

endm



Thats the movement done. All finished! All you really need for a critter. To make it have a lifespan and eventually die is dead easy, and is dealt with in Part 2.






Basic Land Critter Tutorial part 2 - Lifecycle


In this part, we?ll add a subroutine before the movement script as well as a counter which will count how long the critter has lived for. This will allow us to let the critter die and reproduce!

Firstly, add the following lines to the injection script, underneath the rest of the variables:

setv ov01 0

*This next variable sets the life of the critter
*We want it to live for, say, 200 walks
setv ov50 200


ov01 is generally used as the ?life? counter in my scripts, and if I recall correctly it was used as such in Creature Labs? scripts as well. I?m using ov50 as the maximum number of walks the critter can do before dying. You can change this to whatever you want.

Then, in the Timer script above ?gsub walk?, put the following code:

*This is where any counters go.
*We're adding how many walks the critter did to the
*life timer!
addv ov01 ov40

*This is where any subroutines you want to happen go.
*Firstly, the live subroutine, then the movement subroutine.
gsub live
gsub walk


Okay, so now we have a counter which adds the amount of walks the critter did last time the timer script ran through to their age counter, thereby aging the critter. Now, lets take at the subroutine where everything concerning age goes!

*The living subroutine
subr live

*If the 'age' variable equals or is more than
*the lifespan of the critter
doif ov01 >= ov50

*Go to the dying subroutine!
gsub die
endi

*You can also add a piece of code here which will
*give lifestages to your critter, but that won't be
*dealt with here.

retn


Easy! Now we just need to add the dying and birthing subroutines, which are similarly simple.


*The dying subroutine
subr die

*Go to the give birth subroutine
*This ensures that there will always be a Gerana
gsub givebirth

*If the critter was previously going right
doif ov10 = 1

*Slow down the animation, and show the
*dying right animation
anim [20 21 22 23]

*Else if the critter was going left
elif ov10 = 2

*Slow down the animation and show the
*dying left animation
anim [16 17 18 19]
endi

*This will add nutrients to the environment
setv va12 grap posx posy
altr va12 3 0.3

*Delete the dead Gerana
kill ownr
retn


Now for the birthing subroutine, which will create another Gerana to make sure there is never a lack of them!

*The give birth subroutine
subr givebirth

setv va00 posl
setv va01 post

*Inject the Gerana and set properties
new: simp 2 15 21021 "b1-snett" 42 18 2000
attr 194
elas .1
accg 1
perm 100
base 0
frat 2

*Set basic variables all to 0
setv ov40 0
setv ov10 0
setv ov11 0
setv ov01 0

*This next variable sets the life of the critter
*We want it to live for, say, 200 walks
setv ov50 200


*Move to the previously set variables
mvsf va00 va01
tick 1

retn


There... all done! Now, all you have to do is sit back and watch. You can alter many things in this script; how long the critter lives for, whether it has babies, whether it needs nutrients to survive, add lifestages... all through subroutines. Very handy!

You can download the sprites for the Gerana here and download the source code here.

You can download this tutorial in a much clearer, color coded format (.doc) HERE.

Originally published as part of the Creatures Community Spirit Festival 2006.

 


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