Size cannot be used here

hello i am creating a little game and everything was ok before an error appeared:

Could not run the sketch:
size cannot be used here.

here is my code (there is 4 authers classes):

boolean keys[];

int vaisseau_x = 10;
int vaisseau_y = 10;
int vaisseau_width = 50;
int vaisseau_height = 50;
int vaisseau_vitesse = 10;
int vaisseau_munitions = 1000;
int vaisseau_munitions_restantes = vaisseau_munitions + 1;
PImage vaisseau_image;

boolean tir_ouvert = false;

int assaillant_width = 30;
int assaillant_height = 30;
int assaillant_nombre = 100;
PImage assaillant_image;

int powerup_width = 20;
int powerup_height = 20;
int powerup_nombre = 20;
PImage powerup_image;

Assaillant[] assaillants = new Assaillant[assaillant_nombre];
Tir[] tir = new Tir[vaisseau_munitions];
Vaisseau[] vaisseau = new Vaisseau[1];
Powerup[] powerup = new Powerup[powerup_nombre];
void setup(){
  size(1024,768);
  frameRate(60);
  keys = new boolean[3];
  
  for(int i = 0; i < assaillants.length; i++) assaillants[i] = new Assaillant(ceil(random(width, width + 20000)), ceil(random(height - assaillant_height)), 2, ceil(random(30, 255)), assaillant_image);
    for(int i = 0; i < powerup.length; i++) powerup[i] = new Powerup(ceil(random(width, width + 20000)), ceil(random(height - powerup_height)), 5, powerup_image);
  vaisseau[0] = new Vaisseau(vaisseau_x, vaisseau_y, vaisseau_vitesse, vaisseau_image);
  
}

void draw(){
  background(255);
  
  for(int i = 0; i < assaillants.length; i++){
    assaillants[i].affichage();
    assaillants[i].deplacement();
  }
  
  if(tir_ouvert){
    for(int i = 0; i <= vaisseau_munitions - vaisseau_munitions_restantes; i++){
      tir[i].affichage();
      tir[i].deplacement();
    }
  }
  for(int i = 0; i < powerup.length; i++){
    powerup[i].affichage();
    powerup[i].deplacement();
  }
  vaisseau[0].affichage();
  deplacement();
  bordures();
}

void keyPressed(){
  if(key == 'e' || key == 'E') keys[0] = true;
  if(key == 'c' || key == 'C') keys[1] = true;  
  if(key == ' ') keys[2] = true;
}

void keyReleased(){
  if(key == 'e' || key == 'E') keys[0] = false;
  if(key == 'c' || key == 'C') keys[1] = false;
  if(key == ' ') keys[2] = false;
}

void deplacement(){
  if(keys[0] == true) vaisseau[0].pos_y -= vaisseau_vitesse;
  if(keys[1] == true) vaisseau[0].pos_y += vaisseau_vitesse;
  if(keys[2] == true) tirer();
}

void bordures(){
  if(vaisseau_y < 0) vaisseau_y = 0;
  if(vaisseau_y + vaisseau_height > height) vaisseau_y = height - vaisseau_height;
}

void tirer(){
  tir[vaisseau_munitions - vaisseau_munitions_restantes + 1] = new Tir(vaisseau[0].pos_y, 10);
  vaisseau_munitions_restantes -= 1;
  
  tir_ouvert = true;
  keys[2] = false;
}

ty a lot

1 Like

Hey @yonjukyu. It seems that you have forgotten to post the other classes as well. Please post them here too.

Few tips for ya though: :blush:
[1] Use Ctrl + T to autoFormat your code so it is more readable. [Also, Edit > Auto Format]
[2] Use grave accent like this ` your code here ` so that it is formatted here on the forum better.

2 Likes

My speculation is that you used size (,) somewhere outside setup () {} in the other classes. In which case, you should know that size() function must be the first line of code inside setup().

Please refer to this reference to learn more.

2 Likes

To track down the problem, you can use Ctrl-F (Find) to search your sketch for “size”.