[SOLVED]trouble with writing/reading array to/from file

Started by MaximusPrime, March 03, 2012, 22:37:52

Previous topic - Next topic

MaximusPrime

I'm using a mid-point displacement algorithm to generate a map, and the height values are then stored in an array.
The trouble I'm having is loading the numbers back out of the file and into the array when i press F7.

Here's my code for the reader/writer object:
public class Writer {
    
    final int DATA_SIZE = 257;

        FileWriter fw;
        Scanner sc;
        File filename = new File("savedmap.grid");
    
    
    public void write(MPDGenerator mpd) throws IOException{
        
        fw = new FileWriter(filename);
           
        
           fw.write("version=1.0 seed="+mpd.RSEED+"\n");
        for(int j=0;j<DATA_SIZE-1;j++){
            for(int k=0;k<DATA_SIZE-1;k++){
                
                fw.write((int)(mpd.data[j][k]+2000)+"/");
                
            }
            fw.write("\n");
        }
        
        
        
        
    }
    
    public void read(MPDGenerator mpd) throws FileNotFoundException {
        sc = new Scanner(filename).useDelimiter("/");
        sc.nextLine();
        
        for(int j=0;j<DATA_SIZE-1;j++){
            for(int k=0;k<DATA_SIZE-1;k++){
               
                if (sc.hasNextInt()) {
                    mpd.data[j][k] = (sc.nextInt()-2000);
                }
            }
        }
        mpd.print();
    }
    
}


It doesn't give me any Errors, but doesn't reload the map.

mpd.print(); is the method in the generator which converts the height values into a texture array for the renderer(which uses lwjgl)

the +2000 and  -2000 is so it looks neater in the file.

Evil-Devil

Hmm, is the action behind your F7 key ever executed? Actually we only see the save/write logic. Have you testet if the load function is ever called?