please help me with this script i was learning gui in a video and everything was good except for the SDCARD it gave me that it is an object not function and for the missing )
CODE:
var Runnable = java.lang.Runnable;
var PopupWindow = android.widget.PopupWindow;
var Button = android.widget.Button;
var Widget = android.widget;
var LinearLayout = Widget.LinearLayout;
var ViewGroup = android.view.ViewGroup;
var Gravity = android.view.Gravity;
var View = android.view.View;
var AlertDialog = android.app.AlertDialog;
var DialogInterface = android.content.DialogInterface;
var IO = java.io;
var File = IO.File;
var FileOutputStream = IO.FileOutputStream;
var String = java.lang.String;
var Enviroment = android.os.Enviroment;
var BufferedReader = IO.BufferedReader;
var FileReader = IO.FileReader;
var StringBuilder = java.lang.StringBuilder;
var Dialog = android.app.Dialog;
var ScrollView = android.widget.ScrollView;
var EditText = Widget.EditText;
var GUI;
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
function newLevel(){
ctx.runOnUiThread(new Runnable(){
run: function(){
try{
var SDCARD = Enviroment.getExternalStorageDirectory();
GUI = new PopupWindow();
var layout = new LinearLayout(ctx);
var btn = new Button(ctx);
var builder = AlertDialog.Builder(ctx);
builder.setTitle("message");
builder.setMessage("hello");
builder.setNegativeButton("exit", new DialogInterface.OnClickListener(){
onClick: function(di, menu){
di.dismiss
}
});
var alert = builder.create();
alert.show();
}
});
var cf = new Button(ctx);
cf.setText("Create the File");
cf.setOnClickListener(new View.OnClickListener(){
onClick: function(menu){
var f = new File(SDCARD, "text.txt");
var fos = new FileOutputStream(f);
var dialog = new Dialog(ctx);
var scroll = new Dialog(ctx);
var dLayout = new LinearLayout(ctx);
var inputname = new EditText(ctx);
var input = new EditText(ctx);
var create = new Button(ctx);
inputname.setHint("File Name");
input.setHint("Enter text here...");
create.setText("create file");
dialog.setTitle("Create this file");
CODE:
var Runnable = java.lang.Runnable;
var PopupWindow = android.widget.PopupWindow;
var Button = android.widget.Button;
var Widget = android.widget;
var LinearLayout = Widget.LinearLayout;
var ViewGroup = android.view.ViewGroup;
var Gravity = android.view.Gravity;
var View = android.view.View;
var AlertDialog = android.app.AlertDialog;
var DialogInterface = android.content.DialogInterface;
var IO = java.io;
var File = IO.File;
var FileOutputStream = IO.FileOutputStream;
var String = java.lang.String;
var Enviroment = android.os.Enviroment;
var BufferedReader = IO.BufferedReader;
var FileReader = IO.FileReader;
var StringBuilder = java.lang.StringBuilder;
var Dialog = android.app.Dialog;
var ScrollView = android.widget.ScrollView;
var EditText = Widget.EditText;
var GUI;
var ctx = com.mojang.minecraftpe.MainActivity.currentMainActivity.get();
function newLevel(){
ctx.runOnUiThread(new Runnable(){
run: function(){
try{
var SDCARD = Enviroment.getExternalStorageDirectory();
GUI = new PopupWindow();
var layout = new LinearLayout(ctx);
var btn = new Button(ctx);
btn.setText("open");
btn.setOnClickListener(new View.OnClickListener(){
onClick: function(menu){
var builder = AlertDialog.Builder(ctx);
builder.setTitle("message");
builder.setMessage("hello");
builder.setNegativeButton("exit", new DialogInterface.OnClickListener(){
onClick: function(di, menu){
di.dismiss
}
});
var alert = builder.create();
alert.show();
}
});
var cf = new Button(ctx);
cf.setText("Create the File");
cf.setOnClickListener(new View.OnClickListener(){
onClick: function(menu){
var f = new File(SDCARD, "text.txt");
var fos = new FileOutputStream(f);
try{
f.createNewFile();
fos.write(new String("Hello MODPE user").getBytes());
}catch(e){
print("Error: " + e);
}
}
});
layout.addView(btn);
layout.addView(cf);
var dialog = new Dialog(ctx);
var scroll = new Dialog(ctx);
var dLayout = new LinearLayout(ctx);
var inputname = new EditText(ctx);
var input = new EditText(ctx);
var create = new Button(ctx);
inputname.setHint("File Name");
input.setHint("Enter text here...");
create.setText("create file");
dialog.setTitle("Create this file");
dLayout.setOrientation(LinearLayout.VERTICAL);
dLayout.addView(inputname);
dLayout.addView(input);
dLayout.addView(create);
scroll.addView(dLayout);
dialog.setContentView(scroll);
create.setOnClickListener(new View.OnClickListener(){
onClick: function(menu){
var file = new File(SDCARD, inputname.getText().toString() + ".txt");
try {
file.createNewFile();
var fos = new FileOutputStream(file);
fos.write(input.getText().toString().getBytes());
}catch(e){
print("Error: " + e);
}
}
}
GUI = new PopupWindow(layout, ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
GUI.showAtLocation(ctx.getWindow().getDecorView(), Gravity.TOP | Gravity.RIGHT, 0, 0);
}catch(e){
print("Error: " + e);
}
}
});
}
function useItem(x, y, z, itemId, blockId, side){
switch(itemId){
case 280:
var f = new File(Enviroment.getExternalStorageDirectory(), "text.txt");
try {
var br = new BufferedReader(new FileReader(f));
var str;
var data = new StringBuilder();
while((str = br.readLine()) != null){
data.append(str);
data.append("\n");
}
var collected = data.toString();
clientMessage(collected);
}catch(e)
print("Error: " + e);
}
break;
}
}