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

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)


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

1 Like

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.

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?

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

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() {
  for (int i = 0; i<ammo.length; i++) {
    hello h = ammo[i];
void keyPressed() {

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