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

2011/5/27

Error

1
2
Abstract Abstract

2011/5/27

#
cannot find symbol- method move (); I'm trying to do the Crab scenario but Greenfoot doesn't seem to recognize any commands like turn() or move() this happens when i hit the compile button Yes, i checked if the lines were indented correctly.
Abstract Abstract

2011/5/27

#
For the record any thing that Greenfoot doesnt recognize is posted as cannot find symbol- method (insert command here)
Builderboy2005 Builderboy2005

2011/5/27

#
That is probably because Turn() and Move() are not supported Greenfoot methods. Maybe take a look at the Greenfoot API so see what kind of methods you can use? You can find it Here .
Abstract Abstract

2011/5/27

#
but why would the tutorial state to use this command: public void act() { if (Greenfoot.isKeyDown("left")) { turn(-7); } if (Greenfoot.isKeyDown("right")) { turn(7); } move(); }
Builderboy2005 Builderboy2005

2011/5/27

#
It might have defined those methods somewhere else in the program, or it might be extending a specific class that gives Actors those functionalities. Is the actor in question extending a certain class? Can you find those methods in the program?
Abstract Abstract

2011/5/27

#
in fact i can! Check the wombats scenario and look at the source code for the wombats U should find the commands like turn() or move somewhere in there, it shouldn't take long to spot
Abstract Abstract

2011/5/27

#
I'm beginning to think it is the program that is messing up. Could somebody please try using the commands move or turn in Green Foot?
Builderboy2005 Builderboy2005

2011/5/27

#
The reason it can be used in the Wonbats scenario is because the program defines what Move() means:
1
2
3
4
public void move()
    {
       ......
    }
Like i said, Move() is not a default greenfoot command. The only reason Wombats can use it is because they have defined what it means and what it does. To add the functionality you want, try downloading the Mover class from this page and extending your Actor from that class, it will enable you to use Move and Turn like you want.
nccb nccb

2011/5/28

#
Those turn() and move() methods are defined in the starting Crabs scenario, in the Animal class (and Crab inherits from animal). I can think of a few possible reasons you might be having trouble:
  • You've started from scratch rather than using the starting scenario (you can download it here: http://www.greenfoot.org/workshop/little-crab.zip)
  • You are trying to call these methods from a class other than Crab
  • You have accidentally stopped Crab extending Animal (the class file should have the line: class Crab extends Animal)
It's hard to say exactly which one without knowing more, but you are right that those methods should be available to you, and should work.
danpost danpost

2011/5/28

#
A sidenote: Java does not care about whitespace. What I mean is: in your initial post about the "error", you stated that you checked that the lines were indented correctly. The standard indentation is only for the programmer's benefit -- to make it easy to see that each open bracket has a close bracket. The following two sets of code do the same thing First:
1
2
3
if (true) {
    move();
}
Second:
1
if (true) { move(); }
Of course, this is also equivalent to "move();" by itself, because 'true' is always 'true'. But the point is: indentation is not something that affects the way a program works, or does not work; and by no means would cause compilation errors. In fact the method in the tutorial could look like this:
1
2
3
4
5
6
public void act()
{
    if (Greenfoot.isKeyDown("left")) { turn(-7); }
    if (Greenfoot.isKeyDown("right")) { turn(7); }
    move();
}
You can even combine commands in one line like this:
1
2
3
4
5
public void act()
{
    if (Greenfoot.isKeyDown("left")) { turn(-7); move(); }
    if (Greenfoot.isKeyDown("right")) { turn(7); move(); }
}
Actually, I prefer the one-liner for bracketted groups with only one command; and for groups with mutiple commands, I prefer to have the open bracket on a line by itself -- to match with the closed bracket; that way all brackets on the left of the code is paired. No lonely brackets as in the tutorial example you gave with the open bracket at the end of the 'if' statement line (same for the 'for' and 'while' statements).
Swimmer Swimmer

2012/3/6

#
Having the same exact frustration as Abstract. :( Trying to work through the tutorial #2. Have tried "little-crab" and "modern-crab" files. The command the tutorial instructs you to use does not work. (ie move/turn). In little-crab I get this error: "move() in Animal cannot be applied to (int)" So far, I find none of the replies remotely helpful. Disappointed. In modern-crab I get this error: "cannot find symbol -- method move(int)" Regardless as to what the issue is, I find it sad that one should have so much difficulty completing a simple tutorial! Tutorial 2 This is a place for beginners, is it not?
Swimmer Swimmer

2012/3/6

#
Well, I finally made a little progress. With little-crab I changed the line to move(); turn(3); Now, the crab will rotate, however it does not move forward. If there is an error in the move method, why do I need to de-bug that? Humph. I know enough programming to know when the error is me and when it is not. When I'm following a simple tutorial and follow it exactly, I know it is not me. I would like to see this tutorial revised/fixed.
Builderboy2005 Builderboy2005

2012/3/6

#
Have you downloaded the most recent version of Greenfoot? I tried downloading the sample scenarios/tried the code myself and received no issues at all. If you continue to have issues, it might be a good idea to post all of your code so we can get a better look at what you are doing. I can assure you the issue doesn't lie within the tutorial, as the move() command works and is functional, but likely lies on your end, either with code, the version of Greenfoot you have, or some other problem that might have occured during installation.
Swimmer Swimmer

2012/3/6

#
Can anyone tell me if there is an issue with the move method here? /** * Move forward in the current direction. */ public void move() { double angle = Math.toRadians( getRotation() ); int x = (int) Math.round(getX() + Math.cos(angle) * WALKING_SPEED); int y = (int) Math.round(getY() + Math.sin(angle) * WALKING_SPEED); setLocation(x, y); }
Swimmer Swimmer

2012/3/6

#
I'll try to reinstall everything, but to my understanding, I have the latest version of Greenfoot already (2.0.1) (Java version 1.6.0_29)
There are more replies on the next page.
1
2