[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating more turtles



     if pc = black
      [stamp brown
       setc red
       get-away
       stop]

   I want the turtle to create another turtle if it is blue when it goes 
   through this coding.  I have tried adding commands such as sprout and hatch 
   before the "stop", but I keep getting error messages.

If you want a turtle to "give birth" to another turtle. You should be
using the hatch command. The "list" after the hatch command includes
instructions for the newly-created turtle. For example, if you want
the newly-created turtle to always point straight up, you should use
hatch [seth 0]. (Note that the list is enclosed in square brackets.)
If there are no special commands for the new turtle, just use an
"empty list" (square brackets with nothing inside). Since you want the
turtle to "give birth" only if it is blue, you will need a line like
this: if color = blue [hatch [ ]]
Note that you will need to use this line before the setc red
instruction (since none of the turtles will be blue after that).

So, if I understand your case, you'll want something like this...

     if pc = black
      [stamp brown
       if color = blue [hatch [ ]]
       setc red
       get-away
       stop]

I hope this is helpful.

-- Mitchel