# Boolean in parameters

**URL:** <https://discourse.processing.org/t/boolean-in-parameters/7853>\
**Category:** Beginners\
**Created:** [January 26, 2019, 5:07am UTC](https://discourse.processing.org/t/boolean-in-parameters/7853 "2019-01-26T05:07:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dinator14](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@Dinator14](https://discourse.processing.org/u/Dinator14)\
**Post date:** [January 26, 2019, 5:07am UTC](https://discourse.processing.org/t/boolean-in-parameters/7853/1 "2019-01-26T05:07:08Z")

</div>

On the void dead(boolean hit) I get the yellow message saying how the value of the parameter hit is not being used. I’ve realized that putting hit in a conditional statement such as in void show does not bring up this message. What I’m wondering is why I can’t set the parameter hit=true? Is this not possible and/or is there a way to do what I want a different way? I’m assuming that I can’t set hit to true because hit is already predefined as ded which is false when I call the method.

```auto
boolean ded=false;

void setup()
{
  size(800,600);
  background(0);
}

void draw()
{
  show(ded);
  dead(ded);
}

void show(boolean hit)
{
  if(hit==false)
    rect(width/2,height/2,50,50);
}

void dead(boolean hit)
{
  if(key=='a')
    hit=true;
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 26, 2019, 5:21am UTC](https://discourse.processing.org/t/boolean-in-parameters/7853/2 "2019-01-26T05:21:17Z")

</div>

- Function parameters are also local variables.
- Therefore, they cease to exist once its function returns.
- Using the assignment operator [`=`](https://processing.org/reference/assign.html) directly on them is only visible inside its function.
- If you need to retain the value assigned and/or need to access those values everywhere, declare a “global” (a.K.a. field) variable instead.
- Or simply make a function which returns a value.

```auto
boolean ded;

void setup() {
  size(300, 200);
}

void draw() {
  ded = dead();
  getSurface().setTitle("Dead: " + ded);
}

boolean dead() {
  return keyPressed && key == 'a';
}

```

---

<div class="post-metadata">

**Author:** ![Dinator14](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@Dinator14](https://discourse.processing.org/u/Dinator14)\
**Post date:** [January 26, 2019, 5:49am UTC](https://discourse.processing.org/t/boolean-in-parameters/7853/3 "2019-01-26T05:49:29Z")

</div>

So I understand that parameters are local variables and I understand that they can’t be accessed everywhere but I can’t figure out a way to use the boolean dead() method you wrote with drawing and undrawing multiple shapes. For example, if I want to have the show and dead functions that I wrote called twice with different parameters to have 2 different shapes, how would I implement the way you are making the ded boolean true or false. I used my old code to show kind of what I mean because I don’t know how to work yours into it. (Also, in the future I would add more parameters to the dead method to specify which rectangle should show because right now both would undraw if a is clicked)

```auto
boolean ded=false;
boolean ded2=false;

void setup()
{
  size(800,600);
  background(0);
}

void draw()
{
  show(ded,200,200);
  dead(ded);
  show(ded2,500,500);
  dead(ded2);
}

void show(boolean hit, int x, int y)
{
  if(hit==false)
    rect(x,y,50,50);
}

void dead(boolean hit)
{
  if(key=='a')
    hit=true;
}

```

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [January 26, 2019, 5:54am UTC](https://discourse.processing.org/t/boolean-in-parameters/7853/4 "2019-01-26T05:54:15Z")

</div>

> [@Dinator14](#):
>
> … to have 2 different shapes, …

You’re better off creating a `class` to represent each of your “shapes”:

1. [From several variables to arrays - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/8082/from-several-variables-to-arrays)
2. [From several arrays to classes - Processing 2.x and 3.x Forum](http://Forum.Processing.org/two/discussion/8081/from-several-arrays-to-classes)
3. [Objects / Processing.org](http://Processing.org/tutorials/objects/)
