# "ammo" cannot be resolved to a variable \[total beginner\], please help!

**URL:** <https://discourse.processing.org/t/ammo-cannot-be-resolved-to-a-variable-total-beginner-please-help/19123>\
**Category:** Coding Questions\
**Created:** [March 28, 2020, 9:23pm UTC](https://discourse.processing.org/t/ammo-cannot-be-resolved-to-a-variable-total-beginner-please-help/19123 "2020-03-28T21:23:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![CodeNewbie123](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@CodeNewbie123](https://discourse.processing.org/u/CodeNewbie123)\
**Post date:** [March 28, 2020, 9:23pm UTC](https://discourse.processing.org/t/ammo-cannot-be-resolved-to-a-variable-total-beginner-please-help/19123/1 "2020-03-28T21:23:20Z")

</div>

I’m a little bit desperate. Why does Processing say “ammo cannot be resolved to a variable” (Row 52), although i declared the array already in setup? (Row 29)

[https://pastebin.com/T8M2T6Np](https://pastebin.com/T8M2T6Np)

I’ve tried my best, but I’m yet to fully understand Arrays…  
Help would be much appreciated!

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [March 28, 2020, 10:08pm UTC](https://discourse.processing.org/t/ammo-cannot-be-resolved-to-a-variable-total-beginner-please-help/19123/2 "2020-03-28T22:08:59Z")

</div>

Line 7 which declares ammo globally is commented out.  
You then redeclare ammo locally in setup, which is fine, but is not the same variable as line 7.  
When you call ammo in line 52 you are I think referring back to ammo on line 7, which as I said is commented out and therefore inaccessible.

---

<div class="post-metadata">

**Author:** ![CodeNewbie123](https://avatars.discourse-cdn.com/v4/letter/c/58f4c7/32.png) [@CodeNewbie123](https://discourse.processing.org/u/CodeNewbie123)\
**Post date:** [March 28, 2020, 10:14pm UTC](https://discourse.processing.org/t/ammo-cannot-be-resolved-to-a-variable-total-beginner-please-help/19123/3 "2020-03-28T22:14:34Z")

</div>

I did what you said, but now I get the error message

“the type of the expression must be an array type but it resolved to sketch1.Munition” (the class)

What do i do?

---

<div class="post-metadata">

**Author:** ![paulgoux](https://avatars.discourse-cdn.com/v4/letter/p/b9bd4f/32.png) [@paulgoux](https://discourse.processing.org/u/paulgoux)\
**Post date:** [March 28, 2020, 10:26pm UTC](https://discourse.processing.org/t/ammo-cannot-be-resolved-to-a-variable-total-beginner-please-help/19123/4 "2020-03-28T22:26:07Z")

</div>

This should help, replace all instances of hello with the name of the appropriate class, and add the code which you need back in.

```auto

hello[] ammo;
 
 
void settings() {
  size(1300, 900, P3D);
}
 
void setup() {
 ammo = new hello[4];
  for (int i = 0; i<4; i++) {
    ammo[i] = new hello(i,0);
  }
};
 
void draw() {
 background(50);
  for (int i = 0; i<ammo.length; i++) {
    hello h = ammo[i];
    h.show();
    h.move();
  }
}
 
void keyPressed() {
}

class hello{
  float x,y;
  hello(float X,float Y){
    x = X;
    y = Y;
  };
  
  void show(){
    
  };
  
  void move(){
    
  };
  
};

```
