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

2016/8/7

need help for my school project

1
2
danpost danpost

2016/8/20

#
Dayuyu wrote...
at Q world the error is lastworld = world...the word world cannot find symbol..
Remove the parenthesis after 'world' in that line. 'world' is a field -- not a method.
Dayuyu Dayuyu

2016/8/20

#
ok...tq the no error but when i choose the answer at Q world this error pop up...
java.lang.NullPointerException: The given world cannot be null.
	at greenfoot.Greenfoot.setWorld(Greenfoot.java:70)
	at a.act(a.java:23)
	at greenfoot.core.Simulation.actActor(Simulation.java:594)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
	at greenfoot.core.Simulation.runContent(Simulation.java:215)
	at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException: The given world cannot be null.
	at greenfoot.Greenfoot.setWorld(Greenfoot.java:70)
	at b.act(b.java:24)
	at greenfoot.core.Simulation.actActor(Simulation.java:594)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
	at greenfoot.core.Simulation.runContent(Simulation.java:215)
	at greenfoot.core.Simulation.run(Simulation.java:205)
java.lang.NullPointerException: The given world cannot be null.
	at greenfoot.Greenfoot.setWorld(Greenfoot.java:70)
	at a.act(a.java:23)
	at greenfoot.core.Simulation.actActor(Simulation.java:594)
	at greenfoot.core.Simulation.runOneLoop(Simulation.java:552)
	at greenfoot.core.Simulation.runContent(Simulation.java:215)
	at greenfoot.core.Simulation.run(Simulation.java:205)
Dayuyu Dayuyu

2016/8/20

#
i have 4 button at Q world to choose and this the two.. the right answer...
    private World lastWorld;
    public void act() 
    {
        // Add your action code here.
         if (Greenfoot.mouseClicked(this)) {
         win alert_win = new win();
         getWorld().addObject(alert_win, 370, 300); 
         Greenfoot.delay(100);
         Greenfoot.setWorld(lastWorld);
        }
    }    
}
the false answer..
    private World lastWorld;
    public void act() 
    {
        // Add your action code here.
         if (Greenfoot.mouseClicked(this)) {
         loose alert_loose = new loose();
         getWorld().addObject(alert_loose, 370, 300); 
         Greenfoot.delay(100);
         Greenfoot.setWorld(lastWorld);
        }
    }    
}
danpost danpost

2016/8/20

#
The only class that should have a 'lastWorld' field is the Q world class. The buttons need to get that value from the active Q world object using:
Q qWorld = (Q)getWorld(); // get reference to Q world object
Greenfoot.setWorld(qWorld.getLastWorld());
where you add a method in the Q class to get that reference::
public World getLastWorld()
{
    return lastWorld;
}
Dayuyu Dayuyu

2016/8/20

#
ok now the problem solve...thank so much ;).... now i want to ask how i supposed to add score when the answer is correct....
danpost danpost

2016/8/20

#
Dayuyu wrote...
ok now the problem solve...thank so much ;).... now i want to ask how i supposed to add score when the answer is correct....
Get a reference to the Q world (like in the first line above) and call the getter method for the score counter:
Q qWorld = (Q)getWorld();
GameWorld gWorld = (GameWorld)qWorld.getLastWorld(); // replace 'GameWorld' with name of game world class
Counter scoreCounter = gWorld.getScoreCounter();
(you may or may not already have a method in the game world class to get the counter).
Dayuyu Dayuyu

2016/8/20

#
bit confuse.. how many score method do have i put? at Qworld, gameworld do rahmat is supposed to have score method to?
danpost danpost

2016/8/20

#
Dayuyu wrote...
bit confuse.. how many score method do have i put? at Qworld, gameworld do rahmat is supposed to have score method to?
bit uninformed.. I cannot guess as to what you may have already. I did not see anything but a Life in the rahmat class; and nothing in the Q class that deals with anything like a score. You should only have one field to hold the score value and possibly one to hold the Actor object that displays the score value. They should both be in the same class unless the field for the score value is in the class of the actor that displays that value. A getter method for the score value should be in the same class where the score value field is located and, possibly, a getter method should be in the class that has the reference field that holds the Actor object that displays the value. My Value Display Tutorial scenario discusses the different ways to display a value, such as a score value.
Dayuyu Dayuyu

2016/8/21

#
i want to ask how to make the main actor stop when touch the tree(tree is the wall) this is the codding but space between main actor and tree is big...
    public void checkKey()
    {
        if(isTouching(tree.class))
        {
            move(-4);
        }
danpost danpost

2016/8/21

#
Be aware that GreenfootImage objects (as with any java.awt.Image object) is rectangular and that there may be some transparent area to any side of the visible image. These areas are still part of the image and are included during standard collision detection methods. In other words, one image is considered touching another when the images touch, regardless of whether a touching area is transparent or not. This is most likely the source of your problem here. I have created a scenario that will automatically reduce the size of an image to remove any and all excess transparencies that can be removed from the image without destroying any visible part of the image. When you run the scenario, you load the image and then immediately save it to minimize the excess transparency. The scenario is called Image Transparency Adder/Trimmer. You can download it, open it in greenfoot and share it as a stand-alone application so you can use it on demand.
You need to login to post a reply.
1
2