Thread: Gorilla Robot
View Single Post
Super Moderator
Status: Offline
Posts: 250
Join Date: Dec 2012
Location: Frosno, Ca
Default 09-04-2013, 07:17 PM

You have a good start here so don't give up.
The events are correct and the gorillaRobot.goToAnimal method is almost correct (In the Loop you forgot to replace the penguin with the parameter “who.”
So now the gorilla is walking toward whatever you click and when it is close enough the item disappears. This leaves a couple of questions:
1. How do you know if all the animals are gone?
1. How do you know if a particular animal is gone?
2. When does Alice check to see if the animals are all gone?
The first question is answered by writing a function, functions answer questions. The answers a function returns depends on how it is defined in the present case, we are looking for a yes or no i.e. are all the animals gone – yes or no. This runs into the subquestion How can we tell if a particular animal is gone? I am going to leave you with that question and a hint or two.
What changes when an animal is gone? And it is something YOU did in your program. So assuming you have got an answer for that part, now you need to write a Boolean function. Since it involves more than one object, I would create it under the world's functions and call it something descriptive like allGone. In the default Return statement set the value to False. Now drag an If /Else into the function. You can do your checking using nested If/Else or one If/Else and a couple of And functions (the And functions are in the world's function tab.) So it would look something like this:

If “Penguin Gone” And “Dragon Gone” And “Triceratops Gone” Then
Return True
Do Nothing
Return False

So now we have an allGone function that will hopefully return True when all the animals are gone and false otherwise now we just have to use it, which gets us to question 2.
Right now you have a method called “checkIfAllAreGone” this method has (in my opinion) two problems. The first problem is that it sounds like a function that will check if all the animals are gone but it is really a method that will do a bunch of stuff whenever it is called. Whenever it is called is the other problem.
Right now your checkIfAllAreGone is being called exactly once, when the movie starts. When it runs it will carry out the two instructions in the method and exit never to perform again – unless it is called again. There are in general three ways you could cause the method to be called. For the first way ask yourself the question When do I need to check if all the animals are gone? The answer is whenever an animal has gone. So you could put the check in your “goToAnimal” method .

The other two ways both involve checking basically “all the time.” The best way to do this in an event. If you right click on the “when the wold starts” and change it to “While the world is running.” Now checkIfAllAreGone will run continously. But you only want it to run when all the animals are gone so wrap the instructions in checkIfAllAreGone with the an If/Else and the allGone function above.

That should do it.

Mark Henwood
Reply With Quote