this is my code, I want to output a string save in method save ,and use it in load method, but the system seems to take input string as null;
String save;
public void save(){
Actor[] allChess = GWorld.getAllObjects("Chess");
save="";
if(allChess!=null){
for (int i=0; i<allChess.length; i++){
Chess ch = (Chess) allChess[i];
save = save + ch.getX() +" "+ch.getY() +" "+ch.getColor()+" "+ch.getRank()+" "+"Chess";
save =save +"\n";
}
}
System.out.println(save);
this.save = save;
}
public void load(){
while (save.indexOf("\n")>0){
Chess ch;
int x = Integer.valueOf(save.substring(0, save.indexOf(" ")));
save = save.substring(save.indexOf(" ")+1);
int y = Integer.valueOf(save.substring(0, save.indexOf(" ")));
save = save.substring(save.indexOf(" ")+1);
int c = Integer.valueOf(save.substring(0, save.indexOf(" ")));
save = save.substring(save.indexOf(" ")+1);
int r = Integer.valueOf(save.substring(0, save.indexOf(" ")));
String actor = save.substring(0, save.indexOf("\n"));
save = save.substring(save.indexOf("\n")+2);
if ("Chess".equals(actor)&&c==0&&r==1) {
ch = new Chess (Chess.COLOR_RED,Chess.RANK_RAT);
GWorld.addOneObject( ch, x, y);
ch.setImage("red_rat.png");}
}
}
