Do you know why there is an error? I found a new problem

Hello genius!
I posted a question yesterday and it was solved, but I am facing a new problem again, so I am asking you again.

There’s a problem with the first line of code.
It is said that the active mode and static mode were mixed, how can I solve this problem?

int s_num = 40;

PShape s;
PShape b;

Virus Virus1 = new Virus[s_num];
Cell Cells = new Cell[40];

void setup()
{
size(800,600,P3D);

s = loadShape("virus.obj");
b = loadShape("cell.obj");

for(int i =0; i< s_num; i++){
Virus1[i] = new Virus();
}

for(int i=0; i< 1; i++){
Cells[i] = new Cell ();
}

}

void draw()
{
background(0);
for(int i =0; i < s_num; i++){
Virus1[i].display();
Virus1[i].move();
}
for(int i =0; i < 1; i++){
Cells[i].display();
Cells[i].move();
}

}
class Virus{

float xpos,ypos,zpos,speed;

Virus()
{
xpos = random(width);
ypos = random(height);
zpos = random(-200,-400);
speed = random(3,5);
}

void display()
{
noStroke();
fill(#ffcc33);
pushMatrix();
translate(xpos,ypos,zpos);
shape(s,w,w);
popMatrix();
}

void move(){
zpos += speed;
if(zpos > 500 ){
zpos = -200;
}

}

}

class Cell{
float xpos,ypos,zpos,speed,w;

Cell()
{
xpos = mouseX;
ypos = mouseY;
zpos = mouseX;
speed = 5;
w = 0;
}

void display()
{
noStroke();
fill(255,5,188);
pushMatrix();
translate(xpos,ypos,zpos);
shape(b,w,w);
popMatrix();
}

void move()
{
xpos = mouseX;
ypos = mouseY;

}

void draw()
{
int nearestCell;
float minCellDistance =0;

int nearestCell;
float minCellDistance = Float. MAX_VALUE;
for (int i =0; i < s_num; i++){
dist(Cell[0].xpos, Cell[0].ypos, Cell[0].zpos, Virus1[i].xpos,Virus1[i].ypos,Virus1[i].zpos);

}
}

}

}

please use the </> button to format your code …

1 Like

As well as formatting it, please make sure the code can be copied (icon top right of formatted code block) and run without errors (other than the one you are asking about).

1 Like

here is a running version:


int s_num = 40;

PShape s;
PShape b;

Virus[] Virus1 = new Virus[s_num];
Cell[] Cells = new Cell[40];

void setup()
{
  size(800, 600, P3D);

  s = loadShape("virus.obj");
  b = loadShape("cell.obj");

  for (int i =0; i< s_num; i++) {
    Virus1[i] = new Virus();
  }

  for (int i=0; i< 1; i++) {
    Cells[i] = new Cell ();
  }
}

void draw()
{
  background(0);
  for (int i =0; i < s_num; i++) {
    Virus1[i].display();
    Virus1[i].move();
  }
  for (int i =0; i < 1; i++) {
    Cells[i].display();
    Cells[i].move();
  }
}

// =====================================================================

class Virus {

  float xpos, ypos, zpos, speed;

  Virus()
  {
    xpos = random(width);
    ypos = random(height);
    zpos = random(-200, -400);
    speed = random(3, 5);
  }

  void display()
  {
    noStroke();
    fill(#ffcc33);
    pushMatrix();
    translate(xpos, ypos, zpos);
    //shape(s, w, w);
    text("V", 0, 0); 
    popMatrix();
  }

  void move() 
  {
    zpos += speed;
    if (zpos > 500 ) {
      zpos = -200;
    }
  }
  //
}//class

// =====================================================================

class Cell {
  float xpos, ypos, zpos, speed, w;

  Cell()
  {
    xpos = mouseX;
    ypos = mouseY;
    zpos = mouseX;
    speed = 5;
    w = 0;
  }

  void display()
  {
    noStroke();
    fill(255, 5, 188);
    pushMatrix();
    translate(xpos, ypos, zpos);
    //shape(b, w, w);
    text("C", 0, 0); 
    popMatrix();
  }

  void move()
  {
    xpos = mouseX;
    ypos = mouseY;
  }

  void draw()
  {
    int nearestCell;
    float minCellDistance =0;

    // int nearestCell;
    minCellDistance = Float.MAX_VALUE;
    for (int i =0; i < s_num; i++) {
      float d1=dist(Cells[0].xpos, Cells[0].ypos, Cells[0].zpos, 
        Virus1[i].xpos, Virus1[i].ypos, Virus1[i].zpos);
    }
  }
  //
}//class 
//

2 Likes

To add to the recommendations above: you will also get better replies if you use a more descriptive title for your forum post.

If someone reads “Do you know why there is an error? I found a new problem” they do not know whether they will be able to help you or not.

If someone reads “'It looks like you’re mixing active and static modes” they might think “oh I know the answer to that” and jump in to help you out.

You might also find that your question has already been solved by searching online for the error message you get from Processing, like this stakoverflow issue I found by googling the error message your mentioned :wink:

3 Likes

This is mostly caused by misplaced brackets }

One bracket too much or a bracket in a way that code is outside any Function, which isn’t allowed when you work with functions.

1 Like