So I got this code from HERE to try and save an inventory:
var button = new android.widget.Button(ctx);
button.setText("Save Inventory");
button.setOnClickListener(new android.view.View.OnClickListener({
onClick: function(viewarg){
function saveFile (directory, inventory) {
try {
directory = android.os.Environment.getExternalStorageDirectory ().getPath () + "/games/com.mojang/minecraftworlds" + getWorldDir () + "/" + directory; // The file should be saved into the world directory.
var newFile = new java.io.File (directory,inventory);
var directory = new java.io.File (directory);
var success = directory.mkdirs (); // creates the directory if not already created
if (!success){ // if not succeeded
throw new java.io.IOException("Directory "+directory+ "cannot be created"); // throws an IOException. new java.io.IOException(String) has a string parameter as a message.
}
newFile.delete();
/*newFile.createNewFile (); // creates a blank new file*/
var outWrite = new java.io.OutputStreamWriter (new java.io.FileOutputStream (newFile)); // creates the output writer
outWrite.append (Player.getInventorySlot(i));
outWrite.close(); // closes the writer; not necessary to close, but better do it
return false; // tells that it succeeds; not necessary to catch, but better do it
}
catch(thrown){ // catches the error in the try block
return thrown.toString(); // returns a human-readable description of the error. The most common one is java.io.IOException that there is no such file
}
}
function readFile (directory, inventory, wantBytes) { // wantBytes: true or false
try{
directory = android.os.Environment.getExternalStorageDirectory ().getPath () + "/games/com.mojang/minecraftworlds" + getWorldDir () + "/" + directory;
var inFile = new java.io.File(directory,filename);
if (!inFile.isFile()) return "notfile"; // check if it is a file
var inStream = new java.io.FileReader (inFile);
if (wantBytes) {
inStream.read (bytes); // stores the contents into bytes
var bytes = new Array();
return bytes;
}
var inBuffer = new java.io.BufferedReader (inStream);
var line = "",var returner = "";
while ((line = inBuffer.readLine ()) != null) { // read http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine()
returner = returner + line + java.lang.System.getProperty ("line.seperator");
}
return returner;
}
catch(error){
return error.toString();
}
}
}
}));
menuLayout.addView(button);
And now its crashing because I dont know what to put in
So I got this code from HERE to try and save an inventory:
var button = new android.widget.Button(ctx); button.setText("Save Inventory"); button.setOnClickListener(new android.view.View.OnClickListener({ onClick: function(viewarg){ function saveFile (directory, inventory) { try { directory = android.os.Environment.getExternalStorageDirectory ().getPath () + "/games/com.mojang/minecraftworlds" + getWorldDir () + "/" + directory; // The file should be saved into the world directory. var newFile = new java.io.File (directory,inventory); var directory = new java.io.File (directory); var success = directory.mkdirs (); // creates the directory if not already created if (!success){ // if not succeeded throw new java.io.IOException("Directory "+directory+ "cannot be created"); // throws an IOException. new java.io.IOException(String) has a string parameter as a message. } newFile.delete(); /*newFile.createNewFile (); // creates a blank new file*/ var outWrite = new java.io.OutputStreamWriter (new java.io.FileOutputStream (newFile)); // creates the output writer outWrite.append (Player.getInventorySlot(i)); outWrite.close(); // closes the writer; not necessary to close, but better do it return false; // tells that it succeeds; not necessary to catch, but better do it } catch(thrown){ // catches the error in the try block return thrown.toString(); // returns a human-readable description of the error. The most common one is java.io.IOException that there is no such file } } function readFile (directory, inventory, wantBytes) { // wantBytes: true or false try{ directory = android.os.Environment.getExternalStorageDirectory ().getPath () + "/games/com.mojang/minecraftworlds" + getWorldDir () + "/" + directory; var inFile = new java.io.File(directory,filename); if (!inFile.isFile()) return "notfile"; // check if it is a file var inStream = new java.io.FileReader (inFile); if (wantBytes) { inStream.read (bytes); // stores the contents into bytes var bytes = new Array(); return bytes; } var inBuffer = new java.io.BufferedReader (inStream); var line = "",var returner = ""; while ((line = inBuffer.readLine ()) != null) { // read http://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#readLine() returner = returner + line + java.lang.System.getProperty ("line.seperator"); } return returner; } catch(error){ return error.toString(); } } } })); menuLayout.addView(button);And now its crashing because I dont know what to put in Thank you VERY much!