# Decrementing in draw problem

**URL:** https://discourse.processing.org/t/decrementing-in-draw-problem/4879
**Category:** Coding Questions
**Created:** [October 25, 2018, 5:32pm UTC](https://discourse.processing.org/t/decrementing-in-draw-problem/4879 "2018-10-25T17:32:08Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Aquakitty](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aquakitty/32/1906_2.png) [@Aquakitty](https://discourse.processing.org/u/Aquakitty)
#### Post date: [October 25, 2018, 5:32pm UTC](https://discourse.processing.org/t/decrementing-in-draw-problem/4879/1 "2018-10-25T17:32:08Z")

</div>

Hi, new to processing and programming with frames but not to programming so this is a bit embarrassing.  
I’ve managed to make ellipses that expand and contract with no problem by using a state, but I’ve had this other issue a few times with decrementing other things. When I try to decrement, instead of reversing, the thing in question will stay at max and just try to -1 over and over. I thought this was due to not clearing and redrawing (due to framerate) but that seems to not help either.

Here is an example, where when the text hits “STRING\_MAX” i’d like it to start shrinking. Instead, it will hover at 99-100.

```auto
final int SPACE_MIN = 10;
final int SPACE_MAX = 100;
final String message = "howdy!";
int space = 0;
int wordState = 0;
void setup()
{
  size(500, 500);
  space = SPACE_MIN;
  wordState = 0;
}
void draw()
{

  background(0);
  if (space < SPACE_MAX) {
    space ++;
    // wordState = 1;
    drawMessage();
  } else if (space >= SPACE_MAX) {
    clearMessage();
    space --;
    //wordState = 0;
    drawMessage();
  }
  println(space);
}

void drawMessage() {

  for (int i = 0; i < message.length(); i++)
  {
    char c = message.charAt(i);
    text(c, space*i, mouseY);
  }
}

void clearMessage() {
  background(0);
}

```

Thank you!

---

<div class="post-metadata">

### Author: ![Whahahahaha](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@Whahahahaha](https://discourse.processing.org/u/Whahahahaha)
#### Post date: [October 25, 2018, 5:39pm UTC](https://discourse.processing.org/t/decrementing-in-draw-problem/4879/2 "2018-10-25T17:39:28Z")

</div>

well that’s quite obvious right? once space has reached 100, it will execute space-- once, which will make it 99. the next loop it’s smaller than SPACE\_MAX again and increases by 1 (space++).  
a way to solve this would be to activate a trigger once it’s reached SPACE\_MAX and keep subtracting until it reaches SPACE\_MIN (I guess that is eventually what you want?) and when that happens, reverse the trigger or undo it to make it start increasing again

---

<div class="post-metadata">

### Author: ![Aquakitty](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/aquakitty/32/1906_2.png) [@Aquakitty](https://discourse.processing.org/u/Aquakitty)
#### Post date: [October 25, 2018, 5:44pm UTC](https://discourse.processing.org/t/decrementing-in-draw-problem/4879/3 "2018-10-25T17:44:32Z")

</div>

> [@Whahahahaha](#):
>
> a way to solve this would be to activate a trigger once it’s reached SPACE\_MAX and keep subtracting until it reaches SPACE\_MIN (I guess that is eventually what you want?) and when that happens, reverse the trigger or undo it to make it start increasing again

Man, I must have had a total brain meltdown. I knew what was happening and with the way you worded the solution I got it:

```auto
final int SPACE_MIN = 10;
final int SPACE_MAX = 100;
final String message = "howdy!";
int space = 0;
int wordState = 0;
void setup()
{
  size(500, 500);
  space = SPACE_MIN;
  wordState = 0;
}
void draw()
{

  background(0);
  if (space < SPACE_MAX && wordState == 0) {
    space ++;
    drawMessage();
    if (space >= SPACE_MAX){
          wordState = 1;

    }
  } 
  
  if (wordState == 1) {
    clearMessage();
    space --;
        drawMessage();

    if (space <= SPACE_MIN){
    wordState = 0;
    
    }
  }
  println(space);
}

void drawMessage() {

  for (int i = 0; i < message.length(); i++)
  {
    char c = message.charAt(i);
    text(c, space*i, mouseY);
  }
}

void clearMessage() {
  background(0);
}

```

---

<div class="post-metadata">

### Author: ![Whahahahaha](https://avatars.discourse-cdn.com/v4/letter/w/3be4f8/32.png) [@Whahahahaha](https://discourse.processing.org/u/Whahahahaha)
#### Post date: [October 25, 2018, 5:51pm UTC](https://discourse.processing.org/t/decrementing-in-draw-problem/4879/4 "2018-10-25T17:51:25Z")

</div>

😛 I’m glad you got it working. there probably is a better or more elegant solution, but I guess as long as that’s not necessary I don’t see the need for it 😃
