# "dvd cannot be resolved to a variable"

**URL:** <https://discourse.processing.org/t/dvd-cannot-be-resolved-to-a-variable/6876>\
**Category:** Beginners\
**Created:** [December 24, 2018, 1:33pm UTC](https://discourse.processing.org/t/dvd-cannot-be-resolved-to-a-variable/6876 "2018-12-24T13:33:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![C0R4L](https://avatars.discourse-cdn.com/v4/letter/c/5e9695/32.png) [@C0R4L](https://discourse.processing.org/u/C0R4L)\
**Post date:** [December 24, 2018, 1:33pm UTC](https://discourse.processing.org/t/dvd-cannot-be-resolved-to-a-variable/6876/1 "2018-12-24T13:33:29Z")

</div>

I’ve got a different problem while trying to add a sprite and it says "dvd cannot be resolved to a variable

```auto
float x = random(200,300); // x location of square
float y = random(200,300); // y location of square
float xspeed = 1; // speed of square
float yspeed = 1; // speed of square

void setup() {
  size(800, 600);
frameRate(240);
//surface.setResizable(true);
PImage dvd; /// dvd
dvd = loadImage("dvd.png"); /// dvd

}

void draw() {
  background(255);

fill(0,0,0);
rect(0,0,10000,-1);

  // Display the square
  fill(dvd); /// highighted line
  stroke(0);
  rect(x, y, -200, -150);

  // Add speed to location.
  y = y + yspeed;
  x = x + xspeed;
  // bounce
  if(x > width){
    xspeed = xspeed * -1;
  }
  if(y > height){
    yspeed = yspeed * -1;
  }
    if(x < 200){
    xspeed = xspeed * -1;
  }
  if(y < 150){
    yspeed = yspeed * -1;
  }
if (keyPressed) {
    if (key == 'b' || key == 'B') {
      xspeed = xspeed - 0.1f;
      yspeed = yspeed - 0.1f;
    }
  }

```

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 24, 2018, 1:52pm UTC](https://discourse.processing.org/t/dvd-cannot-be-resolved-to-a-variable/6876/2 "2018-12-24T13:52:13Z")

</div>

for variable declaration,  
loading images  
and show them in draw pls use like:

```auto
PImage img;

void setup() {
  size(640, 360);
  img = loadImage("data/moonwalk.jpg");
}

void draw() {
  image(img, 0, 0);
}

```

did you check ?  
[https://processing.org/reference/PImage.html](https://processing.org/reference/PImage.html)

---

<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:** [January 6, 2019, 10:20pm UTC](https://discourse.processing.org/t/dvd-cannot-be-resolved-to-a-variable/6876/3 "2019-01-06T22:20:33Z")

</div>

Just to expand on the above point by [kll](https://discourse.processing.org/u/kll) – if you declare a variable (`PImage dvd`) in `setup()`, then its scope means it is only available in setup, and you get an error when you try to access it elsewhere.

If instead you declare it globally 00 at the top of your sketch – then you can assign it in setup and it is still available globally throughout your sketch. For example, you can define it in `setup()` and use it in `draw()`.
