# Last click and keeping the image

**URL:** <https://discourse.processing.org/t/last-click-and-keeping-the-image/6317>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 5, 2018, 4:00am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317 "2018-12-05T04:00:04Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Missmew72](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Missmew72](https://discourse.processing.org/u/Missmew72)\
**Post date:** [December 5, 2018, 4:00am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/1 "2018-12-05T04:00:04Z")

</div>

So I have a series of clicks setup, each click replaces the last image with the next one. When I get to the last image, I want it to stay even if there is an accidental click afterwards. Is there a way to do this?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 5, 2018, 4:03am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/2 "2018-12-05T04:03:22Z")

</div>

@bryan give you:

```auto
void mousePressed() {
  currentImage += 1;
  if (currentImage > 6) {
    currentImage = 0;
  }
}

```

but you could do:

```auto
void mousePressed() {
  currentImage++;
  if (currentImage > 6) currentImage = 6;
}

```

or

```auto
void mousePressed() {
  currentImage++;
  currentImage = constrain(currentImage,0,6);
}

```

---

<div class="post-metadata">

**Author:** ![Missmew72](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Missmew72](https://discourse.processing.org/u/Missmew72)\
**Post date:** [December 5, 2018, 4:23am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/4 "2018-12-05T04:23:17Z")

</div>

Awesome! The last option worked perfectly! Do you know if there is a way I can now add clicks with new actions without that last image disappearing?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 5, 2018, 4:25am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/5 "2018-12-05T04:25:15Z")

</div>

> [@Missmew72](#):
>
> I can now add clicks with new actions without that last image disappearing?

unclear what you want?

---

<div class="post-metadata">

**Author:** ![Missmew72](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@Missmew72](https://discourse.processing.org/u/Missmew72)\
**Post date:** [December 5, 2018, 4:26am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/6 "2018-12-05T04:26:16Z")

</div>

So if I click again, will I be able to create a new action or event, while still keeping that last image?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [December 5, 2018, 4:35am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/7 "2018-12-05T04:35:56Z")

</div>

yes, there is a wide range of options, but you should think about a  
better operation concept, even if it would mean to learn about GUI libs  
( buttons, sliders… )  
or play with [this](http://kll.engineering-news.org/kllfusion01/articles.php?article_id=154#here13)

but in any case, good style is:

```auto
void setup() {
  // ... the usual things you need here
  println("this is how it works:");
  println("mouse click change image 1 .. 6");
  println("mouse X makes THIS, mouse Y makes THAT ");
}

```

---

<div class="post-metadata">

**Author:** ![bryan](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/bryan/32/2538_2.png) [@bryan](https://discourse.processing.org/u/bryan)\
**Post date:** [December 5, 2018, 11:27am UTC](https://discourse.processing.org/t/last-click-and-keeping-the-image/6317/8 "2018-12-05T11:27:49Z")

</div>

the link proportioned by @kll is really useful. now, you have to understand what are you coding, and try to translate what are you requesting into pseudocode. For example:

> [@Missmew72](#):
>
> Do you know if there is a way I can now add clicks with new actions without that last image disappearing?

so here, you want new actions when you are in the last image, and your last image will be the image 6. so you have to make something like  
`if (currentImage == 6){ image(flr, width/2, height/2); //now you immediately show what i'm guess some buttons so check the button examples in the processing page. //so inside of this statement you now have to add the new function that you want to display }`  
by the way, also look at how the switch function means, `case currentImage` when your currentImage variable is equal to 6, means `if(currentImage == 6)` .  
so in the code you’ll have something like  
`case currentImage: image(flr6, 0, 0); switch(currentButton) { case 0: //functions and display of button0; break; case1: //functions and display of button1; break; } `
