This site requires JavaScript, please enable it in your browser!
Greenfoot back
TNesler
TNesler wrote ...

2019/1/3

Joy of code discrepancies

TNesler TNesler

2019/1/3

#
Hello! If this has been covered before, I apologize. I am working through the Joy of code series and I see that the method "atWorldEdge" has been replaced by "isAtEdge". My problem is that my turtle scenario won't compile. I am getting an error saying "Identifier expected" and then "Illegal start of type". I realize that code changes but it is frustrating when your documentation is out of date. Here is my code:
public class Turtle extends Actor
{
    /**
     * Act - do whatever the Turtle wants to do. This method is called whenever
     * the 'Act' or 'Run' button gets pressed in the environment.
     */
    public void act() 
    {
        move(4);
       if (Greenfoot.getRandomNumber(100) < 10)
       {
           turn (Greenfoot.getRandomNumber(40) - 20);
        }
        
    } 
    
    if (isAtEdge())
    {
    }
}
Thanks for your help!
danpost danpost

2019/1/3

#
Your if block at lines 17 through 19 is outside of any method. What you have is a "hanging" command line. You can move those lines up to before line 15 and it will compile. I am sure this had nothing to do with the age of the video or code changes. By the way, I wonder if the Turtle class in the video extended an Animal class which contained an atWorldEdge method.
TNesler TNesler

2019/1/3

#
Oops! Thanks for seeing that. You are correct. The Trick-the-Turtle Scenario calls the Animal class and then the Turtle class. Unfortunately, I could not find the prebuilt scenario so I made my own. How would I call the Animal class? Looks like I will have to substitute "canSee" with "isTouching" and "eat" with "removeTouching". That's Ok though. As long as the scenario works. Thanks again! Tom Nesler
danpost danpost

2019/1/3

#
TNesler wrote...
How would I call the Animal class?
The Animal class comes with your install. Just use "Edit>Import class..." on the menu bar.
You need to login to post a reply.