Solving C1 CAOS with Nested Doif Statements

Working Out a CAOS Solution in CreaturesI made a plea for CAOS help a couple of days ago, as I was absolutely stumped! A short break proved to be exactly what I needed: It got me thinking much more clearly, and uncovered a mistake I made. Still, the major issue was that I couldn’t figure out how to show lemon buds growing in two different directions. A minor detail, but without the solution, I imagined that it would be impossible in any Creatures 1 COB. The Creatures CAOS Guide briefly mentions nested conditions in doif statements. So I tested this out. A few trials later, and it was actually working! Nested doif statements are quite powerful. Let’s take a quick look at an example!

Nested Doif Statements in Creatures 1

A doif statement, pronounced “do if” statement, defines a set of parameters that must be true in order for a set of instructions to happen. In non-CAOS language, a doif statement might state that if a lemon is not fully grown, it should go through all of its growth stages. Otherwise, it should be able to be interacted with. The updated Creatures 1 carrot was pretty easy with its doif statements. It only grows in one direction. The trouble with my version of the lemons is that I need to have a way to set up a doif statement for poses between two values. I went through doif statement conditions, but concluded that this was impossible. That is, unless you use nested doif statements!

Sample Timer Script with Nested Doif Statements

Please note that this is only a partial script for illustrative purposes, mainly to show how to define parameters for conditions that must be between two values. Feel free to ask for any clarification, or offer up your own ideas!

CAOS Code Explanation
doif pose lt 6 If the pose of the object is less than 6, then the following conditions should be followed. Poses 0-6 correspond to the left-facing lemon buds. Note carefully that the final growth stage does not meet this condition. Why? Read on!
Growth Scripts The exact CAOS has been omitted to keep this simple. It states that the lemon should advance to the next growth stage. Remember how the final growth stage doesn’t meet this condition? If it did, then it would try to advance it to the next image in the sprite file. This will stop growth in the correct spot!
else A quick one! If the above doif statement wasn’t met, then the next instructions should be followed. Her comes our first nested doif statement!
doif pose eq 6 This script is checking if the lemon is exactly equal to pose 6, which is a full grown lemon facing left. Note that it doesn’t overlap with the above statement.
Attribute Scripts For simplicity, this CAOS has also been left out. It simply says that this type of lemon should be visible and can be interacted with. It also turns off the timer script so that it no longer tries to go through any growth stages.
else If the above doif conditions still aren’t true, onward we go!
doif pose gt 12 This script is looking for lemons in poses greater than 12. These are equivalent to full grown right-facing lemons, as well as all of the poses off the vine. In other words, the poses for a held lemon and dropped lemon.
Attribute Scripts This is identical to the attribute scripts above, only we’re applying them to the mature right-facing lemons and other full grown lemon poses.
else Surprise! Onward we go with another else statement!
Growth Scripts The important thing to note here is that these scripts are not preceded by a doif statement. Why? Check over what the previous statements were looking for. They cover poses 0-6 and 12-17. Everything in between hasn’t been defined… Until we get here! With that else statement above, the script applies the following conditions to any lemon that can’t fit into the previous parameters. We get poses 7-11 and, in a roundabout way, can define actions for parameters that fall between two values! These growth scripts apply to right-facing lemon buds.
Here is where I’ve had to fiddle about a little bit. These statements mark the end of the three doif statements, yet I haven’t been entirely sure where the best place is to put these in the script. All seems to work when they’re placed at the very end, but I haven’t found any documentation on the best placement.
endm The mandatory end of any script… We’re done with this one!

Forging Forward with the Updated Creatures 1 LemonIgnoring some placement issues, the lemon buds now grow properly in two different directions! This was quite fun to finally figure out, especially since the lemon trellis can have a little more personality. I’m leaving the spriting fixes for a bit further down the line, although they’re quite simple. My next conundrum involves picking up the lemons… I get an instant crash each time. The good news is that they can be picked up at the right time! Once I can solve this perplexing mystery, the lemons will be quite close to completion. Hopefully everyone will have a pretty lemon trellis to show their Creatures 1 Norns and Grendels very soon!

« Previous Post | Next Post »