Wednesday, September 3, 2014

Wednesday September 3rd, 2014

Today was not a great day for me. I got to class opened my laptop, plugged in my earphones thinking I was going to watch many videos and learn a lot of new things, but it didn't turn out like that.

I opened Greenfoot before watching the videos like I always do, and I clicked run. And there was a problem: every time 2 turtles passed in a world with 6 lettuces, the game didn't stop. I found this weird because I had coded the game to stop only if the turtles had eaten 30 ( each lettuce is worth 5 points) of these lettuces.

I was not thinking very well and spend a good half an hour trying to figure out what the problem was, I even called Tommy to see if he could help me, and he didn't know what to do.  Eventually Mr. Daly came, and he explained to me that when I add a maximum of lettuces to be eaten, it means that ONE turtle has to eat that many lettuces. The reason for why the game didn't stop was because one of the turtles had eaten as an example 4 lettuces, and the other only 2. This means that neither of the turtles had eaten 6 to themselves.

And so I fixed it by doing what Mr. Daly told me to do: by creating one general counter for the both turtles, so that when one turtle ate 4 lettuces and the other ate 2, it would accumulate and would be counted as 6 and the game would stop.

I thought this would be the end of my problems, but I was wrong. So I added two different counters
(as shown below): one of them was called myPoints, and recorded how many lettuces turtle #1 or #2 ate, and just points, which recorded how many lettuces were eaten in total.
At first I only added the "points counter", which worked fine and told me when 6 lettuces were eaten by both turtles, but it did not tell me how many each turtle ate specifically. So then when I added the myPoints, and didn't change anything else: it stopped working.  Unfortunately at this point it was very near the end of class and so I did not have very much time to try and think for a solution to this problem.



After playing around with it at home, I've only managed to find out one thing, which is interesting: the code works and the turtles stop moving after having eaten 6 lettuces, ONLY THE FIRST TIME that the program runs. If I reset it after that, it stops to work and the turtles just keep moving forever.

I will continue to play with it at home. My goal for next class, if of course to find a solution and to get back on track as soon as I can.

No comments:

Post a Comment