Hi JGO,
I am getting errors everytime I am opening a new chunk, but when I am fixing other problems it gets kinda annoying… So I wanted to fix this problem, but I don’t know if there is a way to save a LevelTile[][]…
Currently my saving and loading scripts are:
Saving:
save.writeObject(this.tiles);
Loading:
this.tiles = (LevelTile[][]) load.readObject();
And the whole code (if you want to see this for some reason):
public void saveChunk(){
try {
File file = new File(levelDirectory + "/chunks/chunk[" + x + "," + y + "].dat");
if(file.exists()){
file.delete();
}
FileOutputStream saveFile = new FileOutputStream(levelDirectory + "/chunks/chunk[" + x + "," + y + "].dat");
ObjectOutputStream save = new ObjectOutputStream(saveFile);
save.writeObject(this.tiles);
save.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public void loadChunk(){
try {
File file = new File(levelDirectory + "/chunks/chunk[" + x + "," + y + "].dat");
if(file.exists()){
FileInputStream loadFile = new FileInputStream(levelDirectory + "/chunks/chunk[" + x + "," + y + "].dat");
ObjectInputStream load = new ObjectInputStream(loadFile);
this.tiles = (LevelTile[][]) load.readObject();
System.out.println("CHUNK LOADED");
load.close();
} else {
generateChunk();
System.out.println("CHUNK GENERATED");
}
} catch (Exception e) {
e.printStackTrace();
}
}
If you’ve any questions, please ask!
Thanks already!
-RoseSlayer.