Tick Tock: CAOS and the Carrot Timer Script

The C1 Carrot Timer Script and CAOSOur last practice with CAOS took a look at the default script for dropping a carrot. We’re nearly to the end of the scripts for the default Creatures 1 carrot! Today, our CAOS analysis takes us into the realm of timer scripts. These scripts define what happens when a timer is reached for an object. Recall that from the carrot’s drop script, one line read tick 200. Each time 200 ticks passes, the timer script will execute. In other words, the carrot timer script goes off about every 20 seconds for each carrot. Timer scripts can be used for a number of different functions, but in our example, it controls the carrot growth cycle. It’s the reason why the game knows how to grow carrot seedlings!

CAOS and the C1 Carrot Growth CycleThe recent release of the updated C1 carrot included a number of small fixes, one of which was in the timer script. The original script contains a couple of flaws, as we’ll see in a moment. However, this is a very important CAOS lesson, as it contains a rough blueprint for a food item with a growth cycle. Nothing else in Creatures 1 has multiple growth stages… Although I will spoil a little surprise and say that something is in the works to improve another food source! Take a few moments to go through this annotated bit of CAOS and get an idea of what a timer script does. Hurry: The clock is ticking!

Annotating the Carrot’s Timer Script (2 6 3 9)

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

CAOS Code Explanation
scrp 2 6 3 9 Some programs begin with this line, while others name the file by it. This simply creates a new script for 2 6 3 (carrot) for script number 9 (timer). Everything will happen only when a specified amount of time has passed. This usually occurs in another script, in the format tick x, where x is an integer. Each time this amount of ticks passes, the timer script will be executed.
doif pose lt 5 If the carrot’s pose is less than 5, the following commands should be executed. You may need to use a program to open the sprite file for the carrot (pars.spr) for a visual. Poses 0-4, which meet this criteria, are for the carrot seedlings. So we know that the following instructions only involve immature carrots.
setv attr 64 This sets the object’s attributes, which are vitally important. Note that the value is additive, so that an invisible (16) and wallbound (64) object would have a value of 80. Herein lies the trouble with carrot seedlings: This command sets them as wallbound, or limited to movement in the current room, but does not set them as invisible. Creatures can see the seedlings, but can not interact with them!
setv obv1 pose The setv command is used to set a variable, similar to what happened in the previous command. This one sets object variable 1 (obv1) to whatever the carrot’s current pose is. A very tiny seedling would have obv1 set to 0, while carrots in other growth stages would use whatever pose they’re currently in.
addv obv1 1 Perhaps this looks like gibberish, but it’s actually a simple command once you understand it! The addv portion means that something is going to be added. Guess what? That turns out to be obv1 + 1. This function also sets obv1 equal to the new value. In our example above, where we started with pose 0, this command would set the variable to a value of 1. We’ll use that in the next line!
pose obv1 And… This sets the carrot’s pose to whatever obv1 is equivalent to. In essence, it moves the seedling onto the next growth stage.
tick 200 Here is one of the flaws with the timer script. Remember that the carrot’s drop script already set the number of ticks before the timer script is used. Having this line states that the timer script should go off every 200 ticks… Yet this is already defined elsewhere. Effectively, this does nothing and is an unnecessary line.
endi An uncomplicated CAOS line! It marks the end of the current doif statement.
doif pose gt 4 The above instructions applied to carrots with poses less than 5, and this doif statement applies to all carrots with poses greater than 5. Hence, this applies to full-grown carrots, and not any of the seedling poses.
setv attr 67 This one little line is the reason why mature carrots can be interacted it! Recall that setv means that a variable will be set to a certain value, and attr corresponds to the carrot’s attributes. The value of 67 is additive, so this object will be wallbound (64), mousable (2), and carryable (1). 64 + 2 + 1 = 67 The last two attributes mean that the carrot can be picked up by the hand and Creatures.
tick 0 Setting the tick value to 0 will disable timer events, so the timer script will shut off at this point. Thanks to Grendel Man for the correction!
endi We’ve reached the end of the current doif statement. Are we done yet?
endm Hurray! The end of the script has finally been reached!

Breaking Down the Script Even More

There are a whole lot of commands to achieve a fairly simple result: All carrot seedlings will advance to the next growth stage, while still being visible. Full-grown carrots can be picked up by everyone. That’s it! It may seem overly complicated, yet there are only a couple of unnecessary lines included in the original C1 carrot’s timer script. Soon, I’ll go through some of the CAOS in my updated version to explain what’s been fixed or added, and why. Some have stated that having too many scripts in a world can create the floating egg glitch. The timer script on carrots was pretty much always active, without any value. Perhaps the updates will cut back on those instances! Join me again when we look at the final script for the carrot, and then move onto more CAOS practice!

4 Comments
« Previous Post | Next Post »