# Size cannot be used here

**URL:** <https://discourse.processing.org/t/size-cannot-be-used-here/9765>\
**Category:** Coding Questions\
**Created:** [March 29, 2019, 3:39pm UTC](https://discourse.processing.org/t/size-cannot-be-used-here/9765 "2019-03-29T15:39:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yonjukyu](https://avatars.discourse-cdn.com/v4/letter/y/9de0a6/32.png) [@yonjukyu](https://discourse.processing.org/u/yonjukyu)\
**Post date:** [March 29, 2019, 3:39pm UTC](https://discourse.processing.org/t/size-cannot-be-used-here/9765/1 "2019-03-29T15:39:28Z")

</div>

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):

```auto
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

---

<div class="post-metadata">

**Author:** ![Abel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/abel/32/3289_2.png) [@Abel](https://discourse.processing.org/u/Abel)\
**Post date:** [March 30, 2019, 9:19am UTC](https://discourse.processing.org/t/size-cannot-be-used-here/9765/2 "2019-03-30T09:19:47Z")

</div>

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: 😊  
**[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.

---

<div class="post-metadata">

**Author:** ![Abel](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/abel/32/3289_2.png) [@Abel](https://discourse.processing.org/u/Abel)\
**Post date:** [March 30, 2019, 9:30am UTC](https://discourse.processing.org/t/size-cannot-be-used-here/9765/3 "2019-03-30T09:30:04Z")

</div>

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](https://processing.org/reference/size_.html) reference to learn more.

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [March 30, 2019, 10:20pm UTC](https://discourse.processing.org/t/size-cannot-be-used-here/9765/4 "2019-03-30T22:20:29Z")

</div>

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