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

2011/12/15

not a statement ?

programmer22 programmer22

2011/12/15

#
ive been working on the crab totorial and i some how messed up because i dont have as many yellow boxes asw the picture does but at the end its saying World world; isnt a statement any help?
danpost danpost

2011/12/15

#
We need to know where you have that statement (what class, and where within that class -- exactly).
programmer22 programmer22

2011/12/15

#
not sure how to explain it >.>
danpost danpost

2011/12/15

#
Can you copy and paste what you do have?
programmer22 programmer22

2011/12/15

#
kk
programmer22 programmer22

2011/12/15

#
mport greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo) public class Crab extends Actor { /** * Act - do whatever the Crab wants to do. This method is called whenever * the 'Act' or 'Run' button gets pressed in the environment. */ public void act() { moveAndTurn(); eat(); Move (4); if (Greenfoot.isKeyDown("left")) { { turn(-3); } if (Greenfoot.isKeyDown("right")) { turn(3); } Actor worm; worm = getOneObjectAtOffset (0, 0, Worm.class); { if (worm != null) World world; world = getWorld(); world.Remove0bject(worm); } } its saying that the World world; part isnt a statement but the pic for the worm shows to have that
danpost danpost

2011/12/15

#
You need the open bracket '{' AFTER the 'if' clause (not BEFORE). Also, your first 'if' statement has too many open brackets after it, and the import statement at the beginning is missing the initial 'i' (maybe you did not get it in your copy/pasting).
programmer22 programmer22

2011/12/15

#
umm thanks for the help but can u explain or rewrite that part where the ifs supossed to be after because i cant figure out how i did it last time
danpost danpost

2011/12/15

#
if (Greenfoot.isKeyDown("left"))  
{
    turn(-3);
}
if (Greenfoot.isKeyDown("right"))
{
    turn(3);
}
Actor worm;
worm = getOneObjectAtOffset (0, 0, Worm.class);
 // {     *** removed this one
if (worm != null)
{     //    *** added this one
    World world;
    world = getWorld();
    world.Remove0bject(worm);
}
b321234 b321234

2011/12/15

#
public void act() 
{ 
        moveAndTurn();
        eat();
        Move (4);
}
public void move()
{
        if (Greenfoot.isKeyDown("left")){
                turn(-3);
        }
        if (Greenfoot.isKeyDown("right")){
                turn(3);
        }
}

public void eat()
{
        Actor worm;
        worm = getOneObjectAtOffset (0, 0, Worm.class);
        if (worm != null)
               {
               World world;
               world = getWorld();
               world.Remove0bject(worm);
               }
        }  
} 
b321234 b321234

2011/12/15

#
actually the indentation is pretty weird.. press Ctrl+Shift+I to rearrange the codes, helps a lot ;) It makes it easier to find missing/extra brackets and avoid the reached end of file parsing error
danpost danpost

2011/12/15

#
@b321234, thanks for your response. I was only looking at syntax and bracketing, which appeared to be what was causing the 'World world' "not a statement" issue. Had I looked at context and content, I may have noticed that there were several methods here (not just an act).
b321234 b321234

2011/12/15

#
@danpost, don't worry, I ddn mean that your answer was wrong. Actually I think we posted our answers simultaneously so yeah.. Lol I just wanna show programmer22 the correct codes, no offence =P
danpost danpost

2011/12/16

#
@b321234, Absolutely non taken! I am just glad you were able to supply more exact help to programmer22.
You need to login to post a reply.