The CAOS of Bouncing and Gravity in Albia

Holiday Greetings from Discover AlbiaAlthough rather late, I hope everyone had a Merry Christmas and a wonderful holiday season! I had hoped to return today with a new video, but I received the gift that hasn’t quite stopped giving yet… A lovely virus. My voice is awful and I feel awful, which is no way to enjoy Artemiidae. Luckily, I did have some time to put a new post together! I recently talked about how Creatures 1 simulates gravity, so I started looking at the carrot variant’s drop script. I started annotating… And apparently didn’t stop! This is a monstrous wall of CAOS and text, but this was a really neat learning experience for me. Perhaps you’ll find something new along the way through all 63 lines of the script!

Annotating the Carrot Variant’s Drop Script (2 6 8 5)

I know this is the right script because it corresponds with the class number for the carrot variant (2 6 8), and is for the drop script (script number 5). Feel free to ask if you’d like more details about figuring this out!

CAOS Code Explanation
scrp 2 6 8 5 Some programs begin with this line, while others name the file by it. This simply creates a new script for 2 6 8 (carrot variant) for script number 5 (drop). Everything will happen only when a Creature or the hand drops a carrot variant.
doif pose gt 4 If the carrot variant’s pose is greater than 4, the following commands should be executed. You may need to use a program to open the sprite file for the carrot variant (pars.spr) to understand this better. However, poses for 5 and 6 are for the full grown carrot, while poses 0-4 are for seedlings. Hence, only full grown carrots will continue on with this set of doif (pronounced “do if”) instructions.
setv obv0 0 The setv command is used to set a variable. This one sets object variable 0 (obv0) to a value of 0. This is not actually used anywhere else in this script, so any explanation about what it does in practical terms would be appreciated!
setv actv 1 Again, the setv command means that a variable is being set. In this case, the active variable (actv) is set to a value of 1. As I understand it, this means that the object is currently active and may not be activated again until it has returned to an inactive state. In other words, a bouncing carrot must finish its bouncing and actv must be set to a value of 0 before it can be dropped again.
rndv var0 -5 5 This code sets a variable (var0) to a random variable from -5 to 5. The rndv command is often seen in bouncing scripts because it randomizes at least one variable and ensures that bouncing is unpredictable. If the carrot variant or a toy only bounced up and down, there wouldn’t be the believability of gravity at all! For this example, let’s say that var0 has been set to 2.
setv var1 -11 In a similar way, var1 is another variable that is being set via the setv command. In this case, it is set to a value of -11.
setv var3 0 Repeat! This uses the setv command to set a variable (var3) to a value of 0. Note that these variables do not need to be used in sequential order, but they may only range from var0 to var9. As we’ll see shortly, var2 hasn’t been forgotten!
anim [6] In most instances, the anim command is used to define an animation with multiple poses. This is how various objects move through poses while in apparent motion, such as when the top spins. In this case, only a single pose is defined and an actual animation sequence doesn’t happen. It seems like using the pose function would make more sense, but I’m sure this is something I’ll look into in more detail! The carrot variant simply bounces when laying down.
snde Boun If the object is on the screen, the boun.wav sound will play. Boing! The snde command is always followed by a four-character name of a sound file.
stim writ from 0 -1 0 0 34 60 43 60 22 10 0 0 This is a long command, but it’s not all that bad! The stim writ from means that a stimulus will be will be emitted onto the Creature who is dropping the carrot variant. The portion 0 -1 0 0 is a little beyond the scope of this lesson, but these values define the significance, sensory lobe neuron, intensity, and features. 34 60 is in the format of the chemical number, followed by the amount of it. In other words, this means 60 units of NFP decrease (chemical 34). 43 60 corresponds with 60 units of boredom decrease (chemical 43), while 22 10 means 10 units of tiredness increase (chemical 22). The final 0 0 means that a fourth chemical is not used. A Creature who drops the carrot variant experiences a drop in boredom and NFP, as well as a slight increase in tiredness.
loop This command sets the start of a set of commands that will repeat, or loop, until a set condition is met. This must always be paired with a proper untl statement, which serves as the end of the looped commands and defines the ending condition. We certainly don’t want carrot variants bouncing on into infinity!
mvby var0 var1 To move the carrot variant by a set distance, the mvby command defines the values to move on the x and y axis. In other words, var0 will be the change in the x coordinate (horizontal) and var1 will be the change in the y coordinate (vertical). For our example, this carrot will move 2 on the x axis and -11 on the y axis. The negative value for var1 appears to correspond with the height of the object: Notice that no matter where it is dropped, its actual descent begins rather close to the ground. This is simulated gravity, only in Creatures 1!
doif posl le liml Remember that the doif command (pronounced “do if”) is looking for a criteria to be met. Here, it is checking to see if posl is less than or equal to (le) liml. Whatever does that mean? The posl command is the object’s left coordinate. As shown below, there are other codes to look for other coordinates. The liml portion of this line returns the object’s left limit. I’m still a little murky on how these limits are set, but this is basically checking to see if the carrot variant is headed too far to the left. My understanding is that this is what causes it to bounce off of a wall, rather than travel through it and cause issues.
negv var0 This condition only occurs if the current doif statement is true. So in the case of the carrot variant going too far to the left and outside of the limits, this code turns var0 into its negative (negv). Our example uses a positive value of 2, but this only applies when var0 is a negative value. Think about it on the x axis: Positive numbers will move an object to the right, and negative numbers will move an object to the left.
endi So ends this rather short doif statement so we can move onto…
doif posr ge limr Another doif statement! Feel free to skip over this explanation if the above made sense, because it’s doing something very similar. This time, it is checking to see if posr is greater than or equal to (ge) limr. In other words, the following commands will occur only if the object’s right coordinate is higher than the right limit. This is making sure that the carrot variant isn’t going to travel through a right-hand boundary. Another simulated bounce off a wall!
negv var0 This command is identical to what happened in the previous doif statement. It simply transforms var0 into its negative (negv). Recall that in this example, we imagined that this value is 2. If this moves the carrot variant too far to the right so that it would otherwise go through a wall, this would then turn into -2.
endi Here marks the end of this doif statement. Can you guess what’s next?
doif posb ge limb Yet another doif statement! This is checking to see if posb is greater than or equal to (ge) limb. Hopefully this seems a little clearer after the previous examples! In this case, it is checking to see if the object’s bottom coordinate is greater than the bottom limit. Although the coding is similar, this is actually checking to make sure that the carrot variant still has enough bounce left in it!
doif var1 gt 8 Nested doif statements can add a more complex layer to an object, and the carrot variant is no exception. The important thing to remember that this doif statement will only apply if the previous one is true. So if the carrot variant is no longer high from the ground, this section will be ignored. It is simply checking to see if var1 is greater than (gt) 8. For the first bounce example, var1 is -11.
anim [6] Here is that pesky animation command that doesn’t make a lot of sense to me! For multiple poses, anim ensures that an object is animated through multiple poses. In this case, one pose for the animation seems out of place, but I’ll have to test this out to see how it really works.
else If the most recent doif statement is not true, then this marks the start of the command(s) that should be followed instead. An else command is not required, particularly if nothing special should happen if a doif statement isn’t true.
pose 6 Hurray for a simple code! This sets the object’s pose to 6, which corresponds with a dropped carrot variant.
endi This marks the end of the most recent doif statement. Be very careful with nesting and using the else command! This statement only marks the end of the doif var1 gt 8 code: Everything still applies to the doif statement looking for the bottom limit and the carrot variant’s relative bounciness.
snde Boun Boing! This plays the sound file boun.wav when the object is on the screen.
stim shou 100 1 30 0 0 0 0 0 0 0 0 0 This long command will not take too long to decode. The stim shou means that any Creatures within “shouting” distance will experience the defined effects. As before, the 100 1 30 0 portion is a little outside of the scope of this lesson. Most importantly, it means that the intensity will be set to 100, thereby making a bouncing carrot very interesting to look at! The rest of this command is filled with a whole lot of nothing, which means that no chemicals are emitted. So Creatures can “hear” a bouncing carrot, but this gives them nothing in terms of reducing boredom. This is one of the weaknesses I’ve found in the C1 toys, and this will likely change a bit for the updated carrot variant.
negv var1 Now we get into the heart of the bouncing simulation! This code transforms var1 into its negative (negv). A quick math reminder! The negative of a negative number is a positive. In simpler terms, our example is using -11 for var1. After this command, it will transform into 11. So begins the way that a falling carrot variant will “bounce” off of the ground!
mulv var1 3 More math! In this case, var1 is being multiplied by (mulv) 3. We now have 33.
divv var1 4 Onwards we go with the math functions. This command takes var1 and divides it by 4. Now we have 8.25. This math process may seem long and drawn out, but it slowly reduces the height of each bounce. Remember that this section is in a loop command, so this value will steadily decline. In essence, this is how the carrot variant (and the ball) simulate how gravity is bringing it closer to the ground. It’s actually pretty neat!
doif var0 gt 0 If I see too many doif statements, I begin to pronounce then “doif” instead of “do if”. So here we have another one, simply checking to see if var0 is greater than (gt) 0. Since it’s been awhile, this is the variable used to determine how far to move the object on the x axis, and it was randomized long ago. Assuming that in our example the carrot variant isn’t near any boundaries, var0 should be 2 and will make this doif statement true.
subv var0 1 Math! Subtraction! Yay! This command states that var0 should be subtracted (subv) by 1. That will leave us with 1.
endi So ends this short doif statement. Can you guess what’s next?
doif var0 lt 0 The doif statements continue! This one checks to see if var0 is less than (lt) 0.
addv var0 1 If and only if the last doif statement is true, then var0 is increased (addv) by 1.
endi This marks the end of the last doif statement.
setv var2 var0 As a reminder, we are still within the doif statement looking for the bottom limit. The setv command means that a variable is being set. In this case, var2 will be set to var0. Following our example, this means that var2 is now 1.
addv var2 var1 This command is an addition sequence: It adds (addv) var2 and var1. Most importantly, it also sets var2 equal to the result. Sometimes seeing multiple variables together can be confusing, but in these simple mathematical CAOS commands, the first listed variable is the one being manipulated. Therefore, var2 is now 9.25 (1 + 8.25). Don’t worry: Creatures does this math for you!
doif var2 eq 0 Hello, doif! If var2 is equal to (eq) 0, then the following command(s) apply.
setv var3 1 This command sets the value (setv) of var3 to a value of 1. Simple enough!
endi Farewell, most recent doif statement!
doif var1 lt -4 If anyone isn’t aware of what a doif statement by now, this is a perfect example to nail the idea down! Here, the script is checking to see if var1 is less than (lt) -4. As a quick reminder in the world of negative numbers, a larger negative number is actually lower. So this statement would be true for values like -5 or -6.
anim [6] Animate (anim) that single pose for the carrot variant!
else If the most recent doif statement is not true, then the following command(s) should be followed. Hopefully this is a pretty easy command!
pose 6 Even easier! This sets the pose of the object to 6 so that it is laying down.
endi Here is the end of the road for the last doif statement.
else An else command defines what should happen if a doif statement isn’t true. To clarify, this goes way up the line of code in regards to the bottom limit. The following applies when the carrot variant has reached the bottom limit, thereby being in a rather “bounceless” state and nearing the end of its exciting dance!
addv var1 1 More math! This increases (addv) var1 by 1.
endi Way down here is the end of the doif statement for the bottom limit! It’s easy to see why CAOS scripts can be so long. Color-coding or indenting is something another way to easily see which doif, else, and endi statements go together.
untl var3 eq 1 Another ending! Remember when we first encountered the loop command? It must be paired with a valid untl statement to define when the repetition should come to an end. In this case, the loop continues on until (untl) var3 is exactly equal (eq) to 1. Following this back through the script, var3 only reaches this state when var2 equals 0. On this first bounce, var2 will be 9.25 at this point. I have a feeling that Creatures uses only integers and does rounding, but for the purposes of this example, var3 will only be equivalent to 1 towards the end of a bounce. So the loop ends when there is no bounciness left, as it should be!
pose 6 Now the carrot variant’s pose is set to 6, so it is laying down.
setv var0 hght This command sets a variable (setv) to a set value. In this instance, var0 is set to the object’s height (hght).
setv var1 limb Once again, the value of a variable is set with setv. This script means that var1 is set to the bottom limit (limb).
subv var1 var0 Here, we perform a simple subtraction (subv) equation: var1 minus var0. Remember that this will then set var1 equal to the result.
mvto posl var1 The carrot variant is moved to (mvto) an x, y coordinate defined by posl, var1. In other words, its horizontal position is its current left coordinate, and its vertical position is calculated from the above equations for var1. From my understanding, this should result in the object laying on the ground, neither above nor below. I hope that’s remotely correct! So much CAOS…
setv actv 0 Recall from very early on how the active variable (actv) was set to 1, meaning that the carrot variant was active. This changes it by setting the variable (setv) back to 0, thereby making it inactive. This is a very important part of the process because it means that the object can be interacted with again. Without this, it would still be marked as active and could never be bounced again. One shot carrots are nice, but one bounce carrots are terrible!
else Another else statement! This goes with the doif statement from the very beginning, meaning that the following commands apply to seedlings. This marks the start of a very problematic area that I corrected in the updated C1 carrot, but we’ll look at it for the sake of completion!
setv actv 0 Again, this sets actv to 0, meaning that the carrot seedling can not be eaten until it is dropped and regrown in the garden.
wait 10 This line states to wait a total of 10 ticks before continuing on with the next set of instructions. A single tick is equivalent to approximately 1/10 of a second, so 10 ticks represents about one second in real time.
rndv var0 3400 3800 More randomization! This code is determining a random variable (rndv) for var0 that must be from 3400 to 3800.
mcrt var0 902 This command moves a carrot (mcrt) to a position with x, y coordinates of var0, 902. As a quick reminder, this means that each carrot variant is never actually eaten, but recycled over and over again. As with everything else in this section, this will not appear in the updated version.
tick 200 The tick command assigns the timer rate to a value, which is 200 in this case. Every 200 ticks, which is approximately 20 seconds, the timer script is activated. In a nutshell, it controls the rate of growth of the carrot variant.
endi The last endi statement! Could it be that we reached…
endm The end! Finally!

Breaking Down the Script Even More

Simulating Bouncing and Gravity in CreaturesThat was the longest CAOS script I’ve annotated so far, and it still looks like a monster! It’s actually not that bad: It’s simply controlling the bouncing of the carrot variant and making sure there are boundaries. I still have a few commands to learn more about, but I hope that this shows how complex and simple simulating gravity can be. It certainly takes a lot of mathematical sequences, but most of the script is easy. I have to make many tweaks to incorporate my updates, and I might experiment with the bounciness. However, the improved carrot variant should be bouncing towards you soon!

« Previous Post | Next Post »