We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I try to used output.println to save data (which from println) in a text file, but the data in the output text file is unreadable. I hope some friends can help me solve this problem.
Here is my code:
PrintWriter output;
float x,y,e;
int plate_width=50, plate_height=50;
boolean UP=true;
boolean RIGHT=true;
void setup(){
size(100,100);
x=40;
y=40;
output = createWriter("gcode.doc");
}
void draw(){
if (UP) {
y=y+0.2;
} else {
y=y-0.2;
}
if (y>=plate_height) {
x=x+0.2;
UP=false;
}
if (y<=40) {
UP=true;
x=x+0.2;
}
if (x>plate_width) {
stop();
}
String[] gcode=new String[7];
gcode[0]="G1";
gcode[1]="X";
gcode[2]=str(x);
gcode[3]="Y";
gcode[4]=str(y);
gcode[5]="E";
gcode[6]=str(e);
String[] str=new String[4];
str[0]=gcode[0];
str[1]=gcode[1]+gcode[2];
str[2]=gcode[3]+gcode[4];
str[3]=gcode[5]+gcode[6];
e=e+0.04488;
str=append(str,"");
println(str);
output.println(str);
}
Answers
![RRQQOI1@TEA{ZU7TFZAH@F
Here are two screenshots
If you just wanna output some String[], why not saveStrings()? :-?
https://processing.org/reference/saveStrings_.html
Yes, i did try saveStrings(), but it didn't work. I don't know why, so i try output.println
![E%}O6]({FPG7AF$MCL{F7IL](http://forum.processing.org/two/uploads/imageupload/045/P0GH7GBIS5GE.png
I tried saveStrings, and it only shows this data, that is not what i want.
![](http://forum.processing.org/two/uploads/imageupload/118/YUAFI7DECE01.png
this is what i want
I think it's because str is an array
println converts it to string, output.println doesn't
Chrisir, thank u very much! u r genius!
I can't see your screenshots, but I'd bet what you want is some ".csv" or ".tsv", is it?
You may try out Table class: https://processing.org/reference/Table.html
Then use saveTable() (along w/ dataPath() if you wish) in order to get a proper "output":
https://processing.org/reference/saveTable_.html
GoToLoop, that is look like a good idea! i will try to learn it! Thank u very much!