LWJGL
May 25, 2013, 22:53:16 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: LWJGL is now using GitHub
 
   Home   Help Search Login Register  



Pages: [1]
  Print  
Author Topic: [SOLVED]trouble with writing/reading array to/from file  (Read 778 times)
MaximusPrime
Newbie
*
Posts: 1


« on: March 03, 2012, 14:37:52 »

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:
Code:
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.
Logged
Evil-Devil
Prolific Timewaster
****
Posts: 298



WWW
« Reply #1 on: March 06, 2012, 06:15:58 »

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?
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines
SMFAds for Free Forums
Valid XHTML 1.0! Valid CSS!