[Thread Prev] [Thread Next]
>> 3) Is there a particular reason for having the "moves" slider record
>> alternate moves of the mosquito rather than every move?
> That is a bug. I have not been able to figure out why it does that.
> Can you explain what is happening? It was intended to count each move.
What
> did I do wrong?
Yes, I modified your code to fix the bug. Here is the original piece of
problematic code:
to move
pd
forever [setmoves moves + 1 show distance "t2 fd random 50 wait 10
t1, lt random 360 fd random 50 wait 10 towards "t2]
end
Notice that inside the brackets, you give one command to advance the "moves"
slider (SETMOVES MOVES + 1) but within the same set of brackets you give
TWO commands to move the turtle/mosquito/square forward -- you twice include
FD RANDOM 50. You need to advance the "moves" slider before (or after) each
forward movement of the mosquito, so you need to use the SETMOVES MOVES + 1
command twice in the procedure.
I thought it made more sense to move the mosquito first and then record the
move, although it doesn't really matter because the viewer will see these
happening simultaneously. I made a couple of other changes so that we can
view the distance from the mosquito to its target in a textbox instead of in
the command center, for the purposes of online viewing. That textbox is
called "howfar." So that it wouldn't have a lengthy decimal, I rounded it
off to the nearest integer. So where you included SHOW DISTANCE "T2 I
replaced it with: SETHOWFAR ROUND DISTANCE "T2
I also shortened the FD RANDOM 50 to FD RANDOM 40 because sometimes the
mosquito was flying right through the barrier without being deterred by it.
I enlarged the barrier shape, too, which was only about 8 pixels thick, to
make it closer to 40 pixels thick (and then I shrank the size of the barrier
turtle which had been 130 back to the default size of 40... but still the
mosquito occasionally slips through it. And I also shortened the wait time
to wait 3, since wait 10 was quite slow on my machine. I renamed t1 to be
called "mosquito" since I was getting a bit confused by which turtle was
which, but this also meant that I needed to rename the page entitled
"mosquito" and then needed to rename the buttons on other pages linking to
the mosquito page. I've placed each command on a separate line too. It didn't
seem to matter if the bracketed commands began or ended with the TOWARDS
command, but I bumped that command to the beginning. Anyhow, the only one
of these changes which fixes the "bug" you asked about is that I've used the
command SETMOVES MOVES + 1 twice in the revised procedure:
to move
pd
forever [mosquito, sethowfar round distance "t2
towards "t2
fd random 40
setmoves moves + 1
wait 3
mosquito, lt random 360
fd random 40
setmoves moves + 1
wait 3]
end
So to sum up, now the mosquito aims toward the target, moves forward a random
amount towards it, and the "moves" slider records this move; then the
mosquito turns in any random direction and moves forward a random amount in
that direction, and the "moves" slider records that move, too... and then
this two-move process repeats endlessly: a move towards the target, then a
move in a random direction. Each move is counted on the slider. (Since the
slider is now recording more moves, I increased its maximum from 99 to 200.)
Wendy
Previous by thread:
Re: follow-up on mosquito project
Next by thread:
Re: follow-up on mosquito project
To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.
|