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

2016/11/24

What is the selution

Lars2501 Lars2501

2016/11/24

#
Can someone help me to find the problem?
if (Greenfoot.setWorld(new Super2))
        {
            Greenfoot.delay(10);
        }
Super_Hippo Super_Hippo

2016/11/24

#
What do you want to do there? Where is the code located? The first line can't be used as a condition. The line sets a new world active, how should it be true or false?
Lars2501 Lars2501

2016/11/24

#
This Is my code. But when I will play this game it gives you an error; This error is called: java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:711) at greenfoot.Actor.isTouching(Actor.java:972) at BButton.finish(BButton.java:21) at Super2.act(Super2.java:126) at greenfoot.core.Simulation.actWorld(Simulation.java:610) at greenfoot.core.Simulation.runOneLoop(Simulation.java:545) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211) java.lang.IllegalStateException: Actor not in world. An attempt was made to use the actor's location while it is not in the world. Either it has not yet been inserted, or it has been removed. at greenfoot.Actor.failIfNotInWorld(Actor.java:711) at greenfoot.Actor.isTouching(Actor.java:972) at BButton.finish(BButton.java:21) at Super2.act(Super2.java:120) at greenfoot.core.Simulation.actWorld(Simulation.java:610) at greenfoot.core.Simulation.runOneLoop(Simulation.java:545) at greenfoot.core.Simulation.runContent(Simulation.java:221) at greenfoot.core.Simulation.run(Simulation.java:211)
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Super2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Super2 extends World
{
    /**
     * Constructor for objects of class Super2.
     * 
     */
    private static GreenfootSound backgroundMusic = new GreenfootSound("lvl2.mp3");
    public Super2()
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(12, 12, 60); 
        
        addObject (new Pause2(), 0,0);
        addObject (new Reset2(), 2,0);
        addObject (new BButton(), 3,5);
        addObject (new GButton(), 2,7);
        addObject (new RButton(), 2,6);
        addObject (new Minion(), 2,2);
        addObject (new Hulk(), 3,2);
        addObject (new Ironman(), 2,3);
        addObject (new Spike(), 2,4);
        addObject (new DO(), 2,4);
        addObject (new Spike(), 3,4);
        addObject (new DO(), 3,4);       
        
        /**
         * Aan de bovenkant speelwereld
         */
        addObject (new DO(), 1,1);
        addObject (new DO(), 2,1);
        addObject (new DO(), 3,1);
        addObject (new DO(), 4,1);
        addObject (new DO(), 5,1);
        addObject (new DO(), 6,1);
        addObject (new DO(), 7,1);
        addObject (new DO(), 8,1);
        addObject (new DO(), 9,1);
        addObject (new DO(), 10,1);
        
        /**
         * Aan de onderkant speelwereld
         */
        addObject (new DO(), 1,10);
        addObject (new DO(), 2,10);
        addObject (new DO(), 3,10);
        addObject (new DO(), 4,10);
        addObject (new DO(), 5,10);
        addObject (new DO(), 6,10);
        addObject (new DO(), 7,10);
        addObject (new DO(), 8,10);
        addObject (new DO(), 9,10);
        addObject (new DO(), 10,10);
        
        /**
         * Aan de linkerkant speelwereld
         */
        addObject (new DO(), 1,2);
        addObject (new DO(), 1,3);
        addObject (new DO(), 1,4);
        addObject (new DO(), 1,5);
        addObject (new DO(), 1,6);
        addObject (new DO(), 1,7);
        addObject (new DO(), 1,8);
        addObject (new DO(), 1,9);
        
        /**
         * Aan de rechterkant speelwereld
         */
        addObject (new DO(), 10,2);
        addObject (new DO(), 10,3);
        addObject (new DO(), 10,4);
        addObject (new DO(), 10,5);
        addObject (new DO(), 10,6);
        addObject (new DO(), 10,7);
        addObject (new DO(), 10,8);
        addObject (new DO(), 10,9);
        
        /**
         * In het midden speelwereld
         */
        addObject (new DO(), 4,4);
        addObject (new DO(), 5,4);
        addObject (new DO(), 6,4);
        addObject (new DO(), 7,4);
        addObject (new DO(), 8,4);
        addObject (new DO(), 4,5);
        addObject (new DO(), 5,5);
        addObject (new DO(), 6,5);
        addObject (new DO(), 7,5);
        addObject (new DO(), 8,5);
        addObject (new DO(), 4,6);
        addObject (new DO(), 5,6);
        addObject (new DO(), 6,6);
        addObject (new DO(), 7,6);
        addObject (new DO(), 8,6);
        addObject (new DO(), 4,7);
        addObject (new DO(), 5,7);
        addObject (new DO(), 6,7);
        addObject (new DO(), 7,7);
        addObject (new DO(), 8,7);
        addObject (new DO(), 4,8);
        addObject (new DO(), 5,8);
        addObject (new DO(), 6,8);
        addObject (new DO(), 7,8);
        addObject (new DO(), 8,8);
    }
    private BButton BButton = new BButton();
    private GButton GButton = new GButton();
    private RButton RButton = new RButton();
    public void act()
    {
        if (BButton.finish() && GButton.finish() && RButton.finish())
        {
            Greenfoot.delay(200);
            backgroundMusic.stop();
            Greenfoot.setWorld(new Instructiescherm3());
        }
    }
}

Super_Hippo Super_Hippo

2016/11/24

#
Put lines 115-117 after line 10 (where line 15 should be too). Change lines 23-25. It should not be 'new BButton' etc.. Instead, you use the fields (which are lines 115-117 right now). Btw, variable names should always start with an lowercase letter (if they are not 'final') so you know that it is not a class.
Lars2501 Lars2501

2016/11/24

#
So I have this right now I only have no Idea what I am doing wrong
import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class Super2 here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class Super2 extends World
{
    private BButton bButton = new BButton();
    private GButton gButton = new GButton();
    private RButton rButton = new RButton();
    /**
     * Constructor for objects of class Super2.
     * 
     */
    public Super2()
    {   
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(12, 12, 60); 
        addObject (new Pause2(), 0,0);
        addObject (new Reset2(), 2,0);
        addObject (new private BButton bButton = new BButton(), 3,5);
        addObject (new private GButton gButton = new GButton(), 2,7);
        addObject (new private RButton rButton = new RButton(), 2,6);
        addObject (new Minion(), 2,2);
        addObject (new Hulk(), 3,2);
        addObject (new Ironman(), 2,3);
        addObject (new Spike(), 2,4);
        addObject (new DO(), 2,4);
        addObject (new Spike(), 3,4);
        addObject (new DO(), 3,4);       
        
        //invisible objects. Not important
    }
    public void act()
    {
        if (bButton.finish() && bButton.finish() && rButton.finish())
        {
            Greenfoot.delay(200);
            Greenfoot.setWorld(new Instructiescherm3());
        }
    }
}
danpost danpost

2016/11/24

#
On lines 24 through 26, the first parameter should only be the name of the fields -- 'bButton', 'gButton' and 'rButton' (the buttons were already created and referenced by the fields in lines 11 through 13).
Lars2501 Lars2501

2016/11/24

#
Sorry but I don't get it. Could you make an example of my final code with your tips.
danpost danpost

2016/11/24

#
Lars2501 wrote...
Sorry but I don't get it. Could you make an example of my final code with your tips.
For example, line 24 should be:
addObject(bButton, 3, 5);
Lars2501 Lars2501

2016/11/24

#
thanks dan it worked!!!
You need to login to post a reply.