What is happening to this Array?

Hello, everybody :smiley:
This will be a looong first post.
And the error will be embarrassing minor…

At first click trough this first code (‘s’ to start and then ‘n’ to proceed until nothing happens), then you’ll get a txt document that you’ll need for the error in the second code, that i’m actually looking for (edit the dataPath in line: 124 so it fits for you and do the same in the second code, line:23)


String[] words={"Heimat", "Eltern", "Lernen", "Aufwachsen", "Freundschaft", "Großeltern", 
  "Sicherheit", "Angst", "Liebe"};
int number=0;

boolean start=false;
boolean finish=false;

float hue=360;
float saturation=360;
float brightness=360;
float h = 180;
float s = 180;
float b = 180;

String result="";

String[] count;
int cnt;

void setup() {
  
  size(500, 720);

  //Probantenanzahl aktualisieren

  count = loadStrings("count.txt");
  cnt=int(count[0]);

  //Erzegugen des Farbraumes

  noStroke();
  colorMode(HSB, hue, saturation, brightness);

  for (int i = 0; i < hue; i++) {
    for (int j = 0; j < hue; j++) {
      stroke(i, j, brightness);
      point(i, j);
      stroke(i, saturation, j);
      point(i, 720-j);
    }
  }

  for (int i=0; i<hue; i++) {
    stroke(i, saturation, brightness);
    point(i, 360);
  }

  //Startfenster

  fill(360);
  textSize(18);
  text("Drücke s \nzum starten", 365, 79);
}

void draw() {

  //Erzeugen von Feld am Rand / aktuellem Wort

  noStroke();
  fill(h, s, b);
  rect(360, 180, 140, 360);

  if (start) {
    fill(288);
    rect(361, 70, 140, 30);

    fill(360);
    textSize(20);
    text(words[number], 365, 88);
  }

  if (finish) {
    fill(288);
    rect(361, 50, 140, 80);

    fill(360);
    textSize(18); 
    text("Danke für \nihre Teilnahme", 365, 79);
  }
}

void mousePressed() {
  if (mouseX<361) {
    for (int i = 0; i <= hue; i++) {
      for (int j = 0; j <= hue; j++) {

        //Positionsvergleich zur Farbbestimmung

        if (mouseY<360||mouseY==360) {
          stroke(i, j, brightness);
          point(i, j);
          if (mouseX==i && mouseY==j) {
            h=i;
            s=j;
            b=brightness;
            break;
          }
        } else if (mouseY>360) {
          stroke(i, saturation, j);
          point(i, 720-j);
          if (mouseX==i && mouseY==720-j) {
            h=i;
            s=saturation;
            b=j;
            break;
          }
        }
      }
    }
  }
}

void keyPressed() {
  if (key=='s') {
    start=true;
    fill(288);
    rect(361, 50, 140, 80);
    number=0;
  }
  //Speichern des aktuellen Ergebnisses + nächstes Wort
  else if (key=='n' && number<words.length && start && finish==false) {
    result=result+h+" "+s+" "+b+"*";
    String[] list =split(result, ' ');
    saveStrings("/Users/Chef/Desktop/color_experiment/probanten/probantNr."+cnt+".txt", list);
    if (number<words.length-1) {
      number++;
    } else if (number<words.length && start) {
      finish=true;

      cnt++;
      count[0]=""+cnt;
      saveStrings("count.txt", count);
    }
  }
}

Now the weird part. In this second code are prints to show what the array, allResults, gets (lines: 28 / 33 / 37) and another to show what actually is in the array (line: 50).
Why is every allResults[i][2] just a 0? Except in allResults[0][i] where every number is correct?


//Daten laden

int word=0;
int colr=0;

String[] ldStr;
float[][] allResults=new float[9][3];

//Vormular erzeugen

String[] words={"Heimat", "Eltern", "Lernen", "Aufwachsen", "Freundschaft", "Großeltern", 
  "Sicherheit", "Angst", "Liebe"};

int space=35;
int x=200;
int y=25;
int breit=100;
int tief=50;

void setup() {

  //Laden und filtern der Daten
  ldStr=loadStrings(dataPath("/Users/Chef/Desktop/color_experiment/probanten/probantNr.1.txt"));
  
  for (int i=0; i<ldStr.length; i++) {
    if (i!=0 && i%2==0) {
      String[] num=split(ldStr[i], '*');
      println("num0 "+num[0]);
      allResults[word][colr]=float(num[0]);
      if (i!=18) {
        colr=0;
        word++;
        println("num1 "+num[1]);
        allResults[word][colr]=float(num[1]);
      }
    } else {
      println("ldStr"+i+" "+ldStr[i]);
      allResults[word][colr]=float(ldStr[i]);
      colr++;
    }
  }

  //Ausgabe der Resultate

  size(360, 705);
  
  colorMode(HSB, 360, 360, 360);

  for (int i=0; i<9; i++) {
    println(allResults[i]);
    
    fill(allResults[i][0],allResults[i][1],allResults[i][2]);
    rect(x, y, breit, tief);
    
    textSize(20);
    fill(360);
    text(words[i],space, y+space);
    
    y=y+25+tief;
  }
}

Thank you so much for your time :smile:

1 Like

Du kannst den post editieren, mit dem Stift Symbol.

Bitte markiere dann den Code mit der Maus und klicke das Symbol <\> in der Kommandoleiste des Forums. Danke!

Danke. So siehts gleich viel besser aus :grin:
Jetzt kann man auch den Code lesen, der einer Korrektur bedarf

1 Like

I’ve got it now! I just use hex() and unhex().
Much easier

2 Likes