Generating txt.file in real time

Hi Forum, greetings from Holland.

I want to check all random HSB-values the Mac Book is generating for me in Processing 3.5.4.
So I inserted the next lines:

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - check
println();
println(“A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A A”);
println(rndSB);
println(“H”, hA);
println(“S”, sA);
println(“B”, bA);

// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

Note: not only for A, but also for B, C and D.
Works pretty nice, but alas the number of lines the console is willing to present seems rather limited.

Therefore the next QUESTION: is there a way to collect all text in real time (as “output”) and produce/export one (larger) txt.file?
If yes, how? Thank you in advance.

Welcome to the forum :smile:

The console output window is restricted to how much it can display, removing old output and appending new output. The solution is to store your output in an arraylist and then save it in a simple ASCII text file.

It is unlikely that you can see the whole text file in the console window but will be viewable in its entirety using a text editor e.g. TextEdit.

This sketch demonstrates how to do this and should be easy to adapt to your own sketch.

ArrayList<String> output = new ArrayList<String>();
boolean recording = false;
String filename = "";

void setup() {
  size(640, 480);
  fill(0);
  textSize(20);
  textAlign(LEFT, TOP);
}

void draw() {
  background(200, 200, 255);
  text("Mouse position and click recorder", 10, 20);
  text("Key 1 : start / resume recording", 30, 50);
  text("Key 2 : pause recording", 30, 80);
  text("Key C : clear current log", 30, 110);
  text("Key S : save current log to file", 30, 140);

  text("STATUS :       "+ (recording ? "RECORDING" : "PAUSED"), 30, 200);
  text("LAST FILE LOG :       " + filename, 30, 240);
}

void mouseMoved() {
  if (recording ) {
    output.add("Mouse moved to " + mouseX + "' " + mouseY);
  }
}

void mouseClicked() {
  if (recording ) {
    output.add("Mouse clicked at " + mouseX + "' " + mouseY);
  }
}

void mouseDragged(){
  if (recording ) {
    output.add("Mouse dragged to " + mouseX + "' " + mouseY);
  }
}

void keyTyped() {
  switch(key) {
  case '1':
    recording = true;
    break;
  case '2':
    recording = false;
    break;
  case 'c':
    output.clear();
    break;
  case 's':
    filename = "output-" + millis() + ".txt";
    String[] strings = (String[])output.toArray(new String[output.size()]);
    saveStrings(filename, strings);
  }
}