[Thread Prev] [Thread Next]
On 31 Jan 2008, at 9:49 AM, zehava wizman wrote:
> hello forum!
> I send this problem to LOGO FORUM , some of the friends told me
> that the forum can't read attaced file, so maybe,I could get help
> from you ( as I got good solution some monthes before).
> I use MW Pro ver 1.1
> I have 2 problem:
> 1. When I used the key (space) whenever I want to shoot, Its working
> well till its stopped and an error message "I can't start new
process" ,
> when I used a button (only for shoot) Its working well,WHY?
> 2. Shoot proc checks whether one turtle touches other, then the
> turtle has to be hidden, there is within the if condition an
instruction
> naming the turtle to be hidden, and it doesn't do it. WHY?
> thanks, Zehava
----------
Problem 1.
The MicroWorlds 'when' command launches and independent, parallel
process. That means that the 'when' keeps doing its thing in the
background, forever, unless you specifically use a 'cancel' command
to stop it.
The "I can't start a new process" error is probably due to that. You
see, you launch *brand new* 'when' process, (five of them) every time
you shoot. And you're not telling them all to go away. So eventually
MicroWorlds reaches its built-in limit for the number of processes it
can handle (this is my guess, at least -- I never got the error. But
I use EX on a fairly modern Mac, and you are using Pro: the number of
process allowed could be very different for each of us, especially if
you computer is older).
How to make this go away? Use the 'cancel' command. I simply changed
your 'shoot' procedure to include this at the beginning:
cancel [ touching? "bullet "t1 ]
cancel [ touching? "bullet "t2 ]
cancel [ touching? "bullet "t3 ]
cancel [ touching? "bullet "t4 ]
cancel [ touching? "bullet "t5 ]
This gets rid of any useless 'when' commands from the last bullet
shot -- we don't need them anymore, as that bullet no longer exists.
And we're going to make brand new 'when' commands for the next shot.
You can see this happening live in your 'Processes' tab: there will
be many 'when [ touching ...]' instructions, and they keep on
multiplying.
----------
Problem 2.
This one took me the longest, but it was actually quite simple! Your
turtles are not hiding because you unhide them! In the 'shoot'
procedure, you do hide the plane if it gets shot (with 'ht'). The
trouble is in your 'fly' procedure: it repeats 'forever', and one of
the instructions there, sent to every plane, is 'st'. So right after
you hide a plane that gets shot, you bring it back to life! Oops. :-)
I fixed this by giving each plane a 'clickon' instruction that was
identical to your instructions inside the 'forever' inside 'fly'
*except* I took out the 'st' command. Then, in 'fly' I just asked
each plane to 'clickon'. And then in 'shoot', if a plane gets hit, I
asked it to hide itself with 'ht', and then 'clickoff.' Now, the
plane is not being asked to repeatedly show itself with 'st' inside
the 'forever' loop of fly:
to fly
ask [plane1 plane2 plane3 plane4 plane5]
[ clickon ]
end
; clickon instruction for each plane
to plane_path
seth 270
fd 10
wait 1
setsh 16
setsize 10
end
Showing the planes is an *initialization* action, not something we
want to do repeatedly as they fly. This is a common programming error
to make.
So, to make sure every plane comes back to life at the beginning of a
new game, in the 'start' procedure I asked each plane to show itself
with 'st', in case they were hidden last time because they were shot:
to start
forever [keys]
ask [ plane1 plane2 plane3 plane4 plane5 ]
[ st ]
fly
setpoints 0
bullet,
ht
end
One last tip: in you 'shoot' procedure, you blow up each plane in an
identical way, and repeat that code 5 times. Any time you see
something like this, it's a good place to write a procedure:
when [touching? "bullet "plane1]
[
bullet,
clickoff
ht
plane1,
blowup
]
etc... and then:
; a plane got shot
to blowup
setsize 50
setsh 19
wait 2
ht
setpoints points + 1
clickoff
end
I did my work in EX, as I said above, and you are using Pro, so I
can't give you the modified project. But I'll attach a text file with
the code -- it's heavily modified, but it is mostly cosmetic. I
changed the formatting so that I could understand your code better.
And I moved code out of the turtle's 'instruction' and into the
procedures tab, as 'bullet_path' for the bullet, and 'plane_path' for
the planes. I then changed those turtles' instructions to those
procedures. I also added a 'blowup' procedure to eliminate the
repeated code for blowing up planes. And I gave the planes better
names. And added some comments and indents.
Try and make sure you understand the changes, though -- don't just
copy the code into your project. MicroWorlds works best if *you*
figure it out. See if you can fix your code from this email *before*
looking at my code, preferably without just copying and pasting.
Also, the attached text file with MicroWorlds Logo code has Windows/
DOS line endings. Send me an email if you need Mac/Unix line endings.
I hope this helps.
Sincerely,
Timothy Klein
--
Teacher, OpenWorld Learning
tklein@xxxxxxxxxxxxxxxxxxxxx
Previous by thread:
problem with shoot procedure
Next by thread:
Re: problem with shoot procedure
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.
|