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

2012/4/29

private void in class?

PStigerID PStigerID

2012/4/29

#
In one of my classes I have the following code:
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

public class path17a extends Turtle
{
    public void act() 
    {
        Actor um = getOneIntersectingObject(umL8.class);  
        if(um != null)
            {
                getWorld().removeObjects(getWorld().getObjects(path7intheway.class));
                
                
                
                getWorld().removeObject(this);
            }
    }    
}
    private void one(int x, int y)
        {
getWorld().addObject(new erL8(), x+116 , y+-36 );
getWorld().addObject(new erL8(), x+116 , y+-86 );
getWorld().addObject(new erL8(), x+116 , y+13 );
getWorld().addObject(new erL8(), x+116 , y+63 );
getWorld().addObject(new erL8(), x+116 , y+86 );
getWorld().addObject(new erL8(), x+52 , y+-36 );
getWorld().addObject(new erL8(), x+52 , y+-86 );
getWorld().addObject(new erL8(), x+52 , y+13 );
getWorld().addObject(new erL8(), x+52 , y+63 );
getWorld().addObject(new erL8(), x+52 , y+86 );
        }
Error in line 18: class, interface or enum expected I have something similar in my world( without the getWorld() ) and it works perfectly. I dont see my mistake... I, in the end, just want to be able to write one(x,y) in my act method. Thx PStigerID
danpost danpost

2012/4/29

#
This is because your code between lines 18 and 30 are outside the class code. (move line 17 to line 31). Whenever you get this message, it usually means that there is something wrong with your bracketing.
davmac davmac

2012/4/29

#
Something wrong with your bracketing, as danpost says. If you indented your code correctly (ctrl+shift+I), you would be able to see this immediately.
You need to login to post a reply.