# Novice coder needing help - cannot be resolved to a variable error

**URL:** <https://discourse.processing.org/t/novice-coder-needing-help-cannot-be-resolved-to-a-variable-error/1031>\
**Category:** Coding Questions\
**Created:** [June 17, 2018, 7:11pm UTC](https://discourse.processing.org/t/novice-coder-needing-help-cannot-be-resolved-to-a-variable-error/1031 "2018-06-17T19:11:17Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![JRK](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@JRK](https://discourse.processing.org/u/JRK)\
**Post date:** [June 17, 2018, 7:11pm UTC](https://discourse.processing.org/t/novice-coder-needing-help-cannot-be-resolved-to-a-variable-error/1031/1 "2018-06-17T19:11:17Z")

</div>

I am a beginner and finding a problem. I wrote the following code and had error message “a cannot be resolved to a variable”. The rectangle appears fine with numbers but will not accept a declared integer.

```auto
void setup () {
  size (500,400);
  int a = 100;
} 
 
void draw() {
  rect(a, 100, 200, 200);
}

```

Any help appreciated,  
JRK

---

<div class="post-metadata">

**Author:** ![Kevin](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kevin/32/2297_2.png) [@Kevin](https://discourse.processing.org/u/Kevin)\
**Post date:** [June 17, 2018, 7:14pm UTC](https://discourse.processing.org/t/novice-coder-needing-help-cannot-be-resolved-to-a-variable-error/1031/2 "2018-06-17T19:14:59Z")

</div>

The problem here is that since you’ve declared `a` inside the `setup()` function, it’s only available inside the `setup()` function. If you want variables to be available inside multiple functions, you have to declare them outside the functions. Something like this:

```auto
int a;

void setup () {
  size (500,400);
  a = 100;
}

void draw(){
  rect(a, 100, 200, 200);
}

```

[Here](http://happycoding.io/tutorials/processing/animation#scope) is a bit more info about scope.

---

<div class="post-metadata">

**Author:** ![JRK](https://avatars.discourse-cdn.com/v4/letter/j/65b543/32.png) [@JRK](https://discourse.processing.org/u/JRK)\
**Post date:** [June 17, 2018, 7:20pm UTC](https://discourse.processing.org/t/novice-coder-needing-help-cannot-be-resolved-to-a-variable-error/1031/3 "2018-06-17T19:20:04Z")

</div>

Many thanks. That works much better. Despite having the beginners’ book “Getting Started with Processing” I guess I’ll be using this forum a lot.  
JRK
