# Want to make a little debug mode in my program, need help

**URL:** <https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015>\
**Category:** Coding Questions\
**Created:** [December 7, 2020, 1:31pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015 "2020-12-07T13:31:28Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Braunstein](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/braunstein/32/14262_2.png) [@Braunstein](https://discourse.processing.org/u/Braunstein)\
**Post date:** [December 7, 2020, 1:31pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/1 "2020-12-07T13:31:28Z")

</div>

Hi, im a beginner (like, REALLY beginner) and i want to make a Debug Mode for my program. It shold be activated by pressing “o”, and deactivated with “p” (yes, it is intentional that it is (de-)activated with two different keys.) Here is the code for the debug stuff i have made thus far:

void debugCheck() {  
if (keyPressed) {  
if (key == ‘o’) {  
debug = true;  
} else if (key == ‘p’) {  
debug = false;  
}  
}  
}

void debug() {  
if (debug == true) {  
println(“X:” +mouseX + " Y:" + mouseY);  
fill(255, 0, 0);  
textSize(40);  
text(“DEBUG MODE”, 360, 100);  
}  
}

It does not work at all. I have put both of the functions in the “draw”-loop, but nothing happens when i press “o”. Can someone help…?

---

<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:** [December 7, 2020, 5:03pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/2 "2020-12-07T17:03:38Z")

</div>

This works for me:

```auto
boolean debug=false; 

void setup() {
  size(777, 888);
  background(111);
}

void draw() {
  background(111); 
  debugCheck() ;
  debug();
}

void debugCheck() {
  if (keyPressed) {
    if (key == 'o') {
      debug = true;
    } else if (key == 'p') {
      debug = false;
    }
  }
}

void debug() {
  if (debug) {
    println("X: " +mouseX + " Y: " + mouseY);
    fill(255, 0, 0);
    textSize(40);
    text("DEBUG MODE", 360, 100);
  }
}

```

---

<div class="post-metadata">

**Author:** ![Braunstein](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/braunstein/32/14262_2.png) [@Braunstein](https://discourse.processing.org/u/Braunstein)\
**Post date:** [December 7, 2020, 7:18pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/3 "2020-12-07T19:18:50Z")

</div>

thanks! it appears the only thing different is that i used

```auto
if (debug == true) {

```

instead of just

```auto
if (debug) {

```

i don´t know what that difference that makes in practice, but it works with the rest of my code just fine.

---

<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:** [December 7, 2020, 7:21pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/4 "2020-12-07T19:21:54Z")

</div>

instead of using `if (keyPressed) {` (which is an internal boolean)  
you can use the function of the same name:

_It gets called automatically - no need to call it from draw()._

```auto
void keyPressed() {
 if (key == 'o') {
      debug = true;
    } else if (key == 'p') {
      debug = false;
    }
}

```

---

<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:** [December 7, 2020, 7:23pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/5 "2020-12-07T19:23:07Z")

</div>

> [@Braunstein](#):
>
> i don´t know what that difference that makes in practice,

that makes no difference; the error must be somewhere else

---

<div class="post-metadata">

**Author:** ![Braunstein](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/braunstein/32/14262_2.png) [@Braunstein](https://discourse.processing.org/u/Braunstein)\
**Post date:** [December 7, 2020, 7:33pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/6 "2020-12-07T19:33:52Z")

</div>

oh. okay, that simplifies it a little

---

<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:** [December 7, 2020, 7:35pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/7 "2020-12-07T19:35:31Z")

</div>

but what was your error then?

Please show your initial version of your code

---

<div class="post-metadata">

**Author:** ![Braunstein](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/braunstein/32/14262_2.png) [@Braunstein](https://discourse.processing.org/u/Braunstein)\
**Post date:** [December 7, 2020, 7:40pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/8 "2020-12-07T19:40:49Z")

</div>

here, but i literally just removed " == true" from my original code and it worked.

```auto
void debugCheck() {
  if (keyPressed) {
    if (key == 'o') {
      debug = true;
    } else if (key == 'p') {
      debug = false;
    }
  }
}

void debug() {
  if (debug == true) {
    println("X:" +mouseX + " Y:" + mouseY);
    fill(255, 0, 0);
    textSize(40);
    text("DEBUG MODE", 360, 100);
  }
}

void setup() {
  size(720, 720);
  frameRate(100);
  textAlign(CENTER);
  output = createWriter("save.txt");
}

void draw() {
  background(255);
  //animate();
  //render_generalUI();
  //gameCheck();
  //if (pause == false) {
    renderBoard();
  }
  debugCheck();
  debug();
}

```

(ignore the comments, i just made that so you can run the code without removing these unassigned functions).

---

<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:** [December 7, 2020, 7:44pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/9 "2020-12-07T19:44:40Z")

</div>

can’t see an error there really

```auto

boolean debug=false; 

void debugCheck() {
  if (keyPressed) {
    if (key == 'o') {
      debug = true;
    } else if (key == 'p') {
      debug = false;
    }
  }
}

void debug() {
  if (debug == true) {
    println("X:" +mouseX + " Y:" + mouseY);
    fill(255, 0, 0);
    textSize(40);
    text("DEBUG MODE", 360, 100);
  }
}

void setup() {
  size(720, 720);
  frameRate(100);
  textAlign(CENTER);
  // output = createWriter("save.txt");
}

void draw() {
  background(255);
  //animate();
  //render_generalUI();
  //gameCheck();
  //if (pause == false) {
  // renderBoard();
  //}
  debugCheck();
  debug();
}

```

---

<div class="post-metadata">

**Author:** ![Braunstein](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/braunstein/32/14262_2.png) [@Braunstein](https://discourse.processing.org/u/Braunstein)\
**Post date:** [December 7, 2020, 7:55pm UTC](https://discourse.processing.org/t/want-to-make-a-little-debug-mode-in-my-program-need-help/26015/10 "2020-12-07T19:55:28Z")

</div>

weird…i testet it again and it definetly does not work when i use debug == true instead of just debug. anways there is another problem: it is really inconsistent. sometimes when testing the sketch, the key presses just wont get detected, and i have to, for a reason i absolutely dont get, go into my settings menu inside of my program in order to be able to actiavte the debug mode. it then also works when i am not inside the settings. really confusing…if you want, i can send you the projects code and you can test it yourself.
