# Image not loading in draw method

**URL:** <https://discourse.processing.org/t/image-not-loading-in-draw-method/41511>\
**Category:** Coding Questions\
**Created:** [March 29, 2023, 11:09am UTC](https://discourse.processing.org/t/image-not-loading-in-draw-method/41511 "2023-03-29T11:09:03Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Random\_Ghost](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/random_ghost/32/16609_2.png) [@Random\_Ghost](https://discourse.processing.org/u/Random_Ghost)\
**Post date:** [March 29, 2023, 11:09am UTC](https://discourse.processing.org/t/image-not-loading-in-draw-method/41511/1 "2023-03-29T11:09:03Z")

</div>

I tried creating an image array in the setup method, but no matter what I do, the images won’t show up if I try to draw it in the draw method. It works fine in setup but I need to use it in draw. Any suggestions.

```auto
void setup() {
  size(720, 720);
  background(151);
  PImage[] tiles = new PImage[5];
  tiles[0] = loadImage("C:/Users/sanya/Dropbox/PC/Documents/Processing/Wave function collapse/blank.png");
  tiles[1] = loadImage("C:/Users/sanya/Dropbox/PC/Documents/Processing/Wave function collapse/top.png");
  tiles[2] = loadImage("C:/Users/sanya/Dropbox/PC/Documents/Processing/Wave function collapse/right.png");
  tiles[3] = loadImage("C:/Users/sanya/Dropbox/PC/Documents/Processing/Wave function collapse/bottom.png");
  tiles[4] = loadImage("C:/Users/sanya/Dropbox/PC/Documents/Processing/Wave function collapse/left.png");
}  

void draw() {
  image(tiles[0], 0, 0);
}

```

The error it displays is that the variable tiles does not exist.

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [March 29, 2023, 11:35am UTC](https://discourse.processing.org/t/image-not-loading-in-draw-method/41511/2 "2023-03-29T11:35:07Z")

</div>

> [@Random\_Ghost](#):
>
> `PImage[] tiles = new PImage[5];`

This must be before setup please

---

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [March 29, 2023, 11:43am UTC](https://discourse.processing.org/t/image-not-loading-in-draw-method/41511/3 "2023-03-29T11:43:48Z")

</div>

Hello @Random_Ghost,

This example will help:

> **[Variable Scope / Examples](https://processing.org/examples/variablescope.html)**
>
> Variables have a global or local "scope". For example, variables declared within either the setup() or draw() functions may be only used in these functions. Global variables, variables declared outsid…

`:)`

---

<div class="post-metadata">

**Author:** ![Random\_Ghost](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/random_ghost/32/16609_2.png) [@Random\_Ghost](https://discourse.processing.org/u/Random_Ghost)\
**Post date:** [March 29, 2023, 12:39pm UTC](https://discourse.processing.org/t/image-not-loading-in-draw-method/41511/4 "2023-03-29T12:39:42Z")

</div>

Thanks. It works now.
