# Can't use variable in draw()

**URL:** https://discourse.processing.org/t/cant-use-variable-in-draw/1619
**Category:** Coding Questions
**Created:** [July 9, 2018, 12:58pm UTC](https://discourse.processing.org/t/cant-use-variable-in-draw/1619 "2018-07-09T12:58:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daniel](https://discourse.processing.org/u/Daniel)
#### Post date: [July 9, 2018, 12:58pm UTC](https://discourse.processing.org/t/cant-use-variable-in-draw/1619/1 "2018-07-09T12:58:15Z")

</div>

Hi Folks,

I’m learning processing and I can’t see the forest for the trees…  
Why can’t I use the variable “temp” in draw():

String temp;

public void setup() {

cp5.addButton(“plz0”)  
.setValue(0)  
.setPosition(100,100)  
.setSize(200,19)  
;  
}

public void plz0(int theValue) {  
String temp = str(theValue);  
}

public void draw() {  
println(temp);  
}

println() is only sysing “null”.

Thanks for helping!  
Daniel

---

<div class="post-metadata">

### Author: ![MxFxM](https://avatars.discourse-cdn.com/v4/letter/m/71e660/32.png) [@MxFxM](https://discourse.processing.org/u/MxFxM)
#### Post date: [July 9, 2018, 1:02pm UTC](https://discourse.processing.org/t/cant-use-variable-in-draw/1619/2 "2018-07-09T13:02:08Z")

</div>

> [@Daniel](#):
>
> String temp = str(theValue);

If you use “String” here you create a local variable.  
Just use

```auto
temp = str(theValue);

```

Done.

Max

---

<div class="post-metadata">

### Author: ![Daniel](https://avatars.discourse-cdn.com/v4/letter/d/3ec8ea/32.png) [@Daniel](https://discourse.processing.org/u/Daniel)
#### Post date: [July 9, 2018, 1:12pm UTC](https://discourse.processing.org/t/cant-use-variable-in-draw/1619/3 "2018-07-09T13:12:50Z")

</div>

Praise the lord…

Thanks!

---

<div class="post-metadata">

### Author: ![mat650](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mat650/32/564_2.png) [@mat650](https://discourse.processing.org/u/mat650)
#### Post date: [July 9, 2018, 2:24pm UTC](https://discourse.processing.org/t/cant-use-variable-in-draw/1619/4 "2018-07-09T14:24:10Z")

</div>

You are declaring the variable temp of type String twice: at the beginning of your code as global variable and a second time as local variable in the method plz0() . To assign a value to the global variable temp just remove the type in the method plz0():

```auto
public void plz0(int theVaue){
temp = temp + theValue;
}

```

In this case the argument of the method plz0() is of type int to assign it to a variable of type String you can use concatenation.

You need to cal the method in setup an assign a value as parameter. At this point the variable is initialized and you can print its value in draw().
