# I need help at my beginner idle game

**URL:** <https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432>\
**Category:** Coding Questions\
**Tags:** homework\
**Created:** [December 21, 2020, 10:15pm UTC](https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432 "2020-12-21T22:15:49Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dialias](https://avatars.discourse-cdn.com/v4/letter/d/a698b9/32.png) [@Dialias](https://discourse.processing.org/u/Dialias)\
**Post date:** [December 21, 2020, 10:15pm UTC](https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432/1 "2020-12-21T22:15:49Z")

</div>

Hey there,  
iam a beginner at coding and i wanted to code a clicker game but then this text showed up in the console:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException  
at processing.core.PApplet.runSketch(PApplet.java:10852)  
at processing.core.PApplet.main(PApplet.java:10620)  
Caused by: java.lang.reflect.InvocationTargetException  
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)  
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)  
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)  
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)  
at processing.core.PApplet.runSketch(PApplet.java:10846)  
… 1 more  
Caused by: java.lang.NullPointerException  
at processing.core.PApplet.rect(PApplet.java:12143)  
at Money.(Money.java:50)  
… 6 more  
RuntimeException: java.lang.reflect.InvocationTargetException

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 21, 2020, 10:17pm UTC](https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432/2 "2020-12-21T22:17:53Z")

</div>

It is easier if you post the code. It makes it far faster too and since almost nothing is visible from the error message we can’t help you

---

<div class="post-metadata">

**Author:** ![MiguelSanches](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/miguelsanches/32/11172_2.png) [@MiguelSanches](https://discourse.processing.org/u/MiguelSanches)\
**Post date:** [December 22, 2020, 8:45am UTC](https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432/4 "2020-12-22T08:45:48Z")

</div>

Hi @Dialias

The problem is in your mousePressed function(). You have an extra parentesis  
Try substituting by:

```auto
void mousePressed() {
  if (rx1 <= mouseX && mouseX <= rx1 + rwidth1 &&
    ry1 <= mouseY && mouseY <= ry1 + rheight1) {
    money = money + 1;
  }

  if (rx2 <= mouseX && mouseX <= rx2 + rwidth2 &&
    ry2 <= mouseY && mouseY <= ry2 + rheight2) {
    fill(200, 0, 0);
  }
  rect(rx2, ry2, rwidth2, rheight2);
}

```

You can format your code in the PDE to easily catch this time of errors: Edit -\> Auto format on the PDE tabs (in windows the shortcut is CTRL+T)

Best regards,

---

<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 23, 2020, 11:48pm UTC](https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432/6 "2020-12-23T23:48:01Z")

</div>

I looked into this and it occurred to me that the rect appears only briefly

Using a boolean variable I made it so that the rect appears for 1.2 seconds

```auto

int money;
PImage pic1;
PImage pic2;
int rx1 = 250;
int ry1 = 200;
int rwidth1 = 280;
int rheight1 = 140;
int rx2 = 450;
int ry2 = 400;
int rwidth2 = 480;
int rheight2 = 440;

boolean showRect=false; 
int timer; 

// ------------------------------------------------------------

void setup() {

  size(800, 600);

  money = 0;

  pic1 = loadImage("foto_1.png");
  pic2 = loadImage("foto_2.png");

  noStroke();
}

void draw() {
  background(200);
  println(money);
  textSize(32);
  fill(0);
  text("pic1", 100, 15);
  // pic1.resize(0, 80);
  text("pic2", 250, 200);
  text(money, 50, 60);

  if (showRect) {
    fill(200, 0, 0);
    rect(rx2, ry2, rwidth2, rheight2);
    if (millis()-timer > 1200) {
      showRect=false;
    }
  }
}

// ------------------------------------------------------------

void mousePressed() {
  if (rx1 <= mouseX && 
    mouseX <= rx1 + rwidth1 &&
    ry1 <= mouseY && 
    mouseY <= ry1 + rheight1) {
    money = money + 1;
  }

  if (rx2 <= mouseX &&
    mouseX <= rx2 + rwidth2 &&
    ry2 <= mouseY &&
    mouseY <= ry2 + rheight2) {
  }

  showRect=true;
  timer=millis();
}
//

```

---

<div class="post-metadata">

**Author:** ![mikebrown](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mikebrown/32/16351_2.png) [@mikebrown](https://discourse.processing.org/u/mikebrown)\
**Post date:** [May 30, 2022, 11:53am UTC](https://discourse.processing.org/t/i-need-help-at-my-beginner-idle-game/26432/7 "2022-05-30T11:53:32Z")

</div>

thanks for sharing! I modified this code make something even cool - a [cps counter](https://cpscounter.info). It basically counts the click (like you did) and then added a functionality show rank as per the player’s score. I want help in adding one more feature to save historical scores of the users. Can anyone share something similar?
