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

2014/3/30

Passing a score from one world to another?

1
2
3
4
5
6
trias95 trias95

2014/3/30

#
Sure, I'm just building it now
danpost danpost

2014/3/30

#
I edited my last post. You may not have to upload it now.
trias95 trias95

2014/3/30

#
Oh ive just seen this, good thing too it says its too large. but doing that has the same effect. still no try again button or laughing skull or counter ::/
trias95 trias95

2014/3/30

#
Okay so ive discovere that it is a problem with something in the prepare method. Turns out i made a boo and those things were not loading because i hadnt called the prepare method. However now when i do call it. im getting this null pointer exeption again. ill put the system print line in at the top of the prepare and see if i get anything but im certain its something in the prepare method :/
trias95 trias95

2014/3/30

#
Counter object is null: true Thats what the terminal says when i put it at the top of the prepare method
danpost danpost

2014/3/30

#
Please re-post your GameOver class code as it is now.
trias95 trias95

2014/3/30

#
import greenfoot.*; 
import java.awt.Color;

/**
 * Write a description of class GameOver here.
 * 
 * @author (your name) 
 * @version (a version number or a date)
 */
public class GameOver extends World
{
    
    static GreenfootSound laugh = null;  

    static {  
        laugh = new GreenfootSound("gameOverLaugh.mp3");  
    }
    Counter counter = null;
    
    /**
     * Constructor for objects of class GameOver.
     * 
     */
    public GameOver(Counter counter)
    {    
        // Create a new world with 600x400 cells with a cell size of 1x1 pixels.
        super(800, 600, 1); 
        
           prepare ();
        

        Background.music.stop();
        Survivor.machinegun.stop();
        turretBase.turret.stop();

        this.counter = counter;

        
    }
    public void act() 
    {
        if( !laugh.isPlaying())
        {
            laugh.setVolume(50);
            laugh.playLoop();
        }

    }    
    
    public Counter getCounter()
    {
        return counter;
    }

    /**
     * Prepare the world for the start of the program. That is: create the initial
     * objects and add them to the world.
     */
    private void prepare()
    {
        
        System.out.println("Counter object is null: "+(counter == null)); 
            
        TryAgain tryagain = new TryAgain();
        addObject(tryagain, 681, 551);
        laughingSkull laughingskull = new laughingSkull();
        addObject(laughingskull, 683, 119);
        
        addObject(counter, 462, 575);
        counter.setLocation(454, 568);
        
    }
}
danpost danpost

2014/3/30

#
Please move line 36 up to line 28 (I did mention this before).
trias95 trias95

2014/3/30

#
ive done that, that now again loads the screen without the counter or anything in the prepare method
danpost danpost

2014/3/30

#
Remove the 'System.out.println' statement from the 'prepare' method, compile and try again.
trias95 trias95

2014/3/30

#
Same result, no objects but the screen showss
danpost danpost

2014/3/30

#
Alright. Guess its upload time. I will need to be away for a short time, but I will be back soon.
trias95 trias95

2014/3/30

#
okay great. its too big to uplaod via greenfoot so ill just put the folder in a rar file and onto mediafire if you dont mind. I guess i should take a break. ivee been at this for 2 days now :/
trias95 trias95

2014/3/30

#
https://www.mediafire.com/?cwfhhsi6mm59e1e
danpost danpost

2014/3/30

#
If you have a large sound file, you can remove it and comment out the code to play it; then, upload it on the site. I would prefer to download it from here.
There are more replies on the next page.
1
2
3
4
5
6