PDA

View Full Version : Gorilla Robot


jhernandez25
09-04-2013, 05:29 AM
Ok just wondering if anyone might have any suggestions, am working on chapter 6 question number 16, i can make the Gorilla walk to each animal and make each animal disappear where am having a but of trouble is clicking each animal at random and after the last animal regarless of which one it is the gorilla will spin twice and look at the camera and ask where did every one go, any suggestions??????

chickentree
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:

allGone
If “Penguin Gone” And “Dragon Gone” And “Triceratops Gone” Then
Return True
Else
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.

jhernandez25
09-04-2013, 07:33 PM
Thanks once again I will try ur suggestions and hopefully I can get it to work, and thanks for being detailed :-). I probably would of taken me longer to figure it out especially since am takin the class online durin my deployment with little resources. Ill let u know how it works out form me thanks.

jhernandez25
09-05-2013, 11:33 PM
Wondering if someone could help when ever I add the Move random the gorilla seems to walked through the other anumals any one have an idea on how to fix this?