# I have some simple questions

**URL:** <https://discourse.processing.org/t/i-have-some-simple-questions/39756>\
**Category:** Beginners\
**Created:** [November 17, 2022, 2:29am UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756 "2022-11-17T02:29:52Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![OhiosStrongest](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@OhiosStrongest](https://discourse.processing.org/u/OhiosStrongest)\
**Post date:** [November 17, 2022, 2:29am UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756/1 "2022-11-17T02:29:52Z")

</div>

How do I make it so that only one part of a program executes once?

- I have an animation that when the mouse is pressed the background is changed. However, I only want this to happen once.

How do I make it so that only one specific shape has a stroke(border)?  
Ex: if I have three circles, how do I make it so that only one has a border?

---

<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:** [November 17, 2022, 3:55am UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756/2 "2022-11-17T03:55:33Z")

</div>

> [@OhiosStrongest](#):
>
> - background is changed. However, I only want this to happen once.

You can set a variable `firstTime` (that you would have to add) to `false` when changing your background

Also surround this section where you change the background with

```auto
if(firstTime) {
   ...
}

```

so that the section is executed only once.

**Example**

```auto

boolean firstTime=true;
color bgColor=0; 

void setup() {
  size(600, 600);
}

void draw() {
  background(bgColor); 

  if (mousePressed) {
    if (firstTime) { 
      bgColor=int(random(256)); 
      firstTime=false;
    }
  }
}

```

> [@OhiosStrongest](#):
>
> if I have three circles, how do I make it so that only one has a border?

**For stroke** : before each circle either say `stroke(0);` OR `noStroke();`

- gives either a black (0) border or no border

And welcome to the forum!

Great to have you here!

Chrisir

---

<div class="post-metadata">

**Author:** ![OhiosStrongest](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@OhiosStrongest](https://discourse.processing.org/u/OhiosStrongest)\
**Post date:** [November 17, 2022, 4:21pm UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756/3 "2022-11-17T16:21:35Z")

</div>

Thank you!  
while working with this I came up with another issue: How do I reassign a new value to a variable in the middle of a function?  
ex: Power += 10;  
how do I make it so that the value power is now it’s original value plus 10?

---

<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:** [November 17, 2022, 4:23pm UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756/4 "2022-11-17T16:23:44Z")

</div>

> [@OhiosStrongest](#):
>
> ```
> Power += 10;
> 
> ```

This increases the value by 10. (30 becomes 40).  
Power += 10; is the same as Power = Power + 10;

`Power = 10;` This sets the value to `10`, no matter what the old value is.

- You have also `-=` and `*=` and `/=` iirc
- 

```
       for `Power = Power - 10; Power = Power * 10; Power = Power / 10;`

```

see [Reference / Processing.org](https://processing.org/reference/#control)

---

<div class="post-metadata">

**Author:** ![OhiosStrongest](https://avatars.discourse-cdn.com/v4/letter/o/c4cdca/32.png) [@OhiosStrongest](https://discourse.processing.org/u/OhiosStrongest)\
**Post date:** [November 17, 2022, 4:51pm UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756/5 "2022-11-17T16:51:03Z")

</div>

Allow me to be more specific. If I have a function:  
int Power = 0

void draw(){  
if (mousePressed){  
Power += 10  
}  
}

I am asking: How do I make it so that Power is now the new added value?  
So that Power now equals 10 or whatever value is added to it for how many times the mouse is pressed?

---

<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:** [November 17, 2022, 5:11pm UTC](https://discourse.processing.org/t/i-have-some-simple-questions/39756/6 "2022-11-17T17:11:14Z")

</div>

> [@OhiosStrongest](#):
>
> So that Power now equals 10

`Power = 10;`

Your issue is somewhere else.

draw() runs so fast that **multiple** Mouse Presses are registered during one click when you use `if (mousePressed)`. (as long as you hold the mouse button down)  
That’s why the result of `Power` is too high!

**Solution**

Solution is to use a new function of the same name `mousePressed` that registers each click **only once** :

Instead of `if (mousePressed)` as a variable we can use a function `mousePressed()`.

The function `mousePressed()` gets called automatically on mouse press but only once each time; whereas the variable `if (mousePressed)` registers throughout as long as the mouse button is down.

In the reference they are distinguished by the () that only a function has, not a variable. Note that the help text for mousePressed **is wrong** :

- [mousePressed](https://processing.org/reference/mousePressed.html) : Variable storing if a mouse button is pressed

- [mousePressed()](https://processing.org/reference/mousePressed_.html) : Called once after every time a mouse button is pressed

**Example**

```auto
int Power = 0;

void setup() {
  size(400, 400);
  background(0);
}

void draw() {
  background(0); 
  text(Power, 12, 12);
}

void mousePressed() { // function mousePressed() !!!!!!!!!!!
  Power += 10;
}

```

Warm regards,

Chrisir
