My sketch doesn't run, can anybody help me?

int AH=4; // Anzahl der Memorykarten in der Höhe
int AB=6; // Anzahl der Memorykarten in der Breite
float rh; // Abstand zwischen dem Bildschirmrand und den Memorykarten in der Höhe
float rb; // Abstand zwischen dem Bildschirmrand und den Memorykarten in der Breite
float h; // Abstand zwischen rh 1 und rh 2
float b; // Abstand zwischen rb 1 und rb 2
float m; // Länge & Breite der Memorykarten
float a; // Abstand zwischen den Memorykarten

int value = 0; // ???
PImage[] img; // Bilderarray
int imnr = 0; // Bildnummer
int[ ] karten; // Kartenarray
int[] kartenstatus; /* 0: schwarze Seite der Karte wird gezeichnet, 1: Bild wird gezeichnet(= Karte aufgedeckt), 2: Kartenpaar wurde richtig aufgedeckt, 
 wird nicht mehr gezeichnet 
 */


// aufgedeckt;
void setup() {
  fullScreen();
  rh=height/10;
  rb=width/10;
  h=height - 2*rh;
  b=width - 2*rb;
  m=(b/(1.1*AB-0.1))*0.95;
  a=m/10; 

  kartenstatus = new int[AH*AB];
  for (int i=0; i<kartenstatus.length; i++) {
    kartenstatus[i]=0;
    draw();
  }

  kartenstatus[5] = 2;
}// Kartenstatus wird festgelegt
// To Do:

void draw () { 
  background (255);
  zeichneSchrift();
  imnr=0;
  zeichneMemorykarten();

  imageMode(CORNER) // Bilder werden geladen
    img = new PImage[18];

  for (int i=0; i<img.length; i++) {
    img[i]= loadImage ("Bilder/image"+i+".jpg");
  }
  karten = new int[AH*AB]; // Kartenpärchen werden zugeordnet
  for (int i = 0; i< karten.length; i++) {
    karten[i] = i/2;
  }

  for (int i=0; i<karten.length; i++) { // Karten werden mithilfe eines Zufallswertes durchmischt, bis jede Karte mindestens einmal getauscht wurde
    int x = int(random(AH*AB));
    int dummy = karten[i];
    karten[i] = karten[ ];
    karten[ ] = dummy;
  }
  for (int i=0; i<karten.length; i++) { // momentan noch zur Kontrolle, ob Durchmischungsprozess funktioniert
    print(" "+karten[i]);
  }
}
void zeichneSchrift () { // Schrift wird gezeichnet
  textSize(20);
  fill(0);
  text ("Spieler A", 30, 30);
  text ("gewonnene Paare:", 30, 60);
  text ("Spieler B", 956, 30); 
  text ("gewonnene Paare:", 956, 60);
}

void zeichneMemorykarten () {
  for (int i=0; i<AB; i++) {  
    for (int j=0; j<AH; j++) {
      if (kartenstatus[j*AB+i]==0) { // wenn der Kartenstatus 0 ist, wird die schwarze Seite der Karten gezeichnet
        stroke(255);
        fill(0);
        rect (rb+i*(m+a), rh+j*(m+a), m, m);
      } else if (kartenstatus[j*AB+i]==1) {// wenn der Kartenstatus 1 ist, wird das Bild gezeichnet; To Do: darf pro zug nur 2-mal durchlaufen!!!
        image (img[karten[j*AH+i]], rb+i*(m+a), rh+j*(m+a), m, m );
        imnr++;
        if (imnr>=18) imnr=0;
      }
    }
  }
}

void karteAnklicken(int x, int y) { // Kartenstatus einer Karte wird abgefragt
  if (kartenstatus[x*y]=0) kartenstatus[x*y] = 1;
  else kartenstatus[x*y]= 1;
}

mouseReleased(); 
{
  int x=-1;
  int y = -1;
  x= ((int)mouseX- (int)rb)/((int)m+(int)a);
  println(mouseX);
  y= ((int)mouseY- (int)rh)/((int)m+(int)a);
  println (mouseY);

  karteAnklicken(x, y);
}
}

/that’s what’s written on the console:
“expecting SEMI, found ‘img’
Syntax error, maybe a missing semicolon?”
/

In processing, as with most programming languages, you have to explicitly include a multiplication sign between a constant and a variable. So for example, your line

h=height - 2rh;

leaves the compiler confused because it doesn’t understand what rh is doing there after the 2. Try

h=height - 2*rh;

and so on.

There might be other issues there too; try clicking on the ‘Errors’ tab on the bottom of the Processing app to see more.

2 Likes

Your post has been edited to format the code for better readability. Please review our FAQ or refer to the animation below for guidance on posting code. Thank you!

ezgif.com-gif-maker (1)

Hello @joshg,

That is what happens when the do not format code properly when posting to the forum.

The admins have since cleaned it up.

This is the formatted code if it is just cut and paste into a sketch:

Unformatted code < Click to expand!

int AH=4; // Anzahl der Memorykarten in der Höhe
int AB=6; // Anzahl der Memorykarten in der Breite
float rh; // Abstand zwischen dem Bildschirmrand und den Memorykarten in der Höhe
float rb; // Abstand zwischen dem Bildschirmrand und den Memorykarten in der Breite
float h; // Abstand zwischen rh 1 und rh 2
float b; // Abstand zwischen rb 1 und rb 2
float m; // Länge & Breite der Memorykarten
float a; // Abstand zwischen den Memorykarten

int value = 0; // ???
PImage img; // Bilderarray
int imnr = 0; // Bildnummer
int karten; // Kartenarray
int kartenstatus; /* 0: schwarze Seite der Karte wird gezeichnet, 1: Bild wird gezeichnet(= Karte aufgedeckt), 2: Kartenpaar wurde richtig aufgedeckt,
wird nicht mehr gezeichnet
*/

// aufgedeckt;
void setup() {
fullScreen();
rh=height/10;
rb=width/10;
h=height - 2rh;
b=width - 2
rb;
m=(b/(1.1*AB-0.1))*0.95;
a=m/10;

kartenstatus = new int[AH*AB];
for (int i=0; i<kartenstatus.length; i++) {
kartenstatus[i]=0;
draw();
}

kartenstatus[5] = 2;
}// Kartenstatus wird festgelegt
// To Do:

void draw () {
background (255);
zeichneSchrift();
imnr=0;
zeichneMemorykarten();

imageMode(CORNER) // Bilder werden geladen
img = new PImage[18];

for (int i=0; i<img.length; i++) {
img[i]= loadImage (“Bilder/image”+i+“.jpg”);
}
karten = new int[AH*AB]; // Kartenpärchen werden zugeordnet
for (int i = 0; i< karten.length; i++) {
karten[i] = i/2;
}

for (int i=0; i<karten.length; i++) { // Karten werden mithilfe eines Zufallswertes durchmischt, bis jede Karte mindestens einmal getauscht wurde
int x = int(random(AH*AB));
int dummy = karten[i];
karten[i] = karten;
karten = dummy;
}
for (int i=0; i<karten.length; i++) { // momentan noch zur Kontrolle, ob Durchmischungsprozess funktioniert
print(" "+karten[i]);
}
}
void zeichneSchrift () { // Schrift wird gezeichnet
textSize(20);
fill(0);
text (“Spieler A”, 30, 30);
text (“gewonnene Paare:”, 30, 60);
text (“Spieler B”, 956, 30);
text (“gewonnene Paare:”, 956, 60);
}

void zeichneMemorykarten () {
for (int i=0; i<AB; i++) {
for (int j=0; j<AH; j++) {
if (kartenstatus[jAB+i]==0) { // wenn der Kartenstatus 0 ist, wird die schwarze Seite der Karten gezeichnet
stroke(255);
fill(0);
rect (rb+i
(m+a), rh+j*(m+a), m, m);
} else if (kartenstatus[jAB+i]==1) {// wenn der Kartenstatus 1 ist, wird das Bild gezeichnet; To Do: darf pro zug nur 2-mal durchlaufen!!!
image (img[karten[j
AH+i]], rb+i*(m+a), rh+j*(m+a), m, m );
imnr++;
if (imnr>=18) imnr=0;
}
}
}
}

void karteAnklicken(int x, int y) { // Kartenstatus einer Karte wird abgefragt
if (kartenstatus[xy]=0) kartenstatus[xy] = 1;
else kartenstatus[x*y]= 1;
}

mouseReleased();
{
int x=-1;
int y = -1;
x= ((int)mouseX- (int)rb)/((int)m+(int)a);
println(mouseX);
y= ((int)mouseY- (int)rh)/((int)m+(int)a);
println (mouseY);

karteAnklicken(x, y);
}
}

The * is a problem because Processing Discourse uses Markdown, where * denotes italics or bold. This can mess up code formatting unless it’s properly enclosed in code blocks.

:)

Ah, that makes sense! I didn’t realize this forum supports Markdown.

OP, looks like you’re just missing a semicolon in this line:
imageMode(CORNER) // Bilder werden geladen

Even after that I can’t run the posted code on a Mac:
Syntax Error - editor.status.error_on
I have no idea how to fix that.

That error message is pretty cryptic!

Hrm, it really is weird that the IDE isn’t jumping to the error on trying to run.

If you go to the error panel, you can click on the error to jump to what’s causing a problem. The weird ‘editor.status.error_oasdfsadfsadf’ ones seem to refer to a mismatch of accessing array variables with or without an index, eg. karten[i] = karten[ ];

The mouseReleased function is also formatted poorly and won’t run; it needs ‘void’ and some correct punctuation around it.

1 Like

On a Mac my error panel is empty; which operating system are you using? There are lots of problems with the code and I finally gave up.

Well that’s even weirder. I’m on Linux at the moment.

Hey, thanks for sharing your code!

There are a few issues preventing your sketch from running as expected:

  • First, you’re calling draw(); manually inside setup(), which isn’t necessary. Processing calls it in a loop automatically.
  • Second, you’re loading images inside draw(). That means they will be loaded every frame. That should happen only once in setup().
  • There are some more syntax errors throughout, including missing semicolons and other issues.

I’d recommend reviewing how setup() and draw() are intended to work in Processing, and moving your image loading and initialization logic out of draw(). Once those things are fixed, the rest should be easier to debug.

1 Like

Hello @sableraph,

I was just looking at this code as a morning exercise for my brain!

And your response popped in!

I call that electromagnetic waves propagating through space… and I picked up on them!

There are many errors indeed!

Just one more that I am leaving as an exercise for the original poster:

Reference:

:)

1 Like

It seems to work with Processing 3.5.4

I believe something is broken now in the recent versions.

I did not find an issue here but may have missed something:

:)