# Referencing colour value I defined in the main project again in class after redefining it in class?

**URL:** <https://discourse.processing.org/t/referencing-colour-value-i-defined-in-the-main-project-again-in-class-after-redefining-it-in-class/40308>\
**Category:** Beginners\
**Created:** [December 26, 2022, 12:16am UTC](https://discourse.processing.org/t/referencing-colour-value-i-defined-in-the-main-project-again-in-class-after-redefining-it-in-class/40308 "2022-12-26T00:16:02Z")\
**Posts on this page:** 1\
**Showing post:** 6

<div class="post-metadata">

**Author:** ![debxyz](https://avatars.discourse-cdn.com/v4/letter/d/58956e/32.png) [@debxyz](https://discourse.processing.org/u/debxyz)\
**Post date:** [December 26, 2022, 6:03pm UTC](https://discourse.processing.org/t/referencing-colour-value-i-defined-in-the-main-project-again-in-class-after-redefining-it-in-class/40308/6 "2022-12-26T18:03:40Z")

</div>

Hello @MarkusWiesinger

This post by @jeremydouglass might be of use:

> [@How can I restart the program with keypress](https://discourse.processing.org/t/how-can-i-restart-the-program-with-keypress/15446/27):
>
> One simple way of approaching restart-timing is to rerun your setup each time you restart, and maintain a global variable with the last time you restarted. This lets you compute either the total run time (millis) or the current runtime (restart-millis). Processing always runs setup on frame 0 – so one way to rerun it (and reset frameCount at the same time) is to set the frameCount to -1. /\*\* \* Restart Frame 0 \* 2019-11 Processing 3.4 \* Press key to restart -- setup() runs again on the foll…

But because we can see only the class code and not the main program I had to kind of imagine the other variables at play.

For example, when you say:

> [@MarkusWiesinger](#):
>
> But, I also want the game to be endless.  
> So when I win the game, it should reset with a keypress.

Does **endless** here mean that there is an accumulation of a score that remains intact that you build upon when you reset?  
Or does everything reset to the original default settings?

Also, regarding the `boolean end` in:

> [@MarkusWiesinger](#):
>
> ```auto
> if (end == true) {
> fill(col);
> invisible = false;
> 
> ```

I’m assuming this is declared and initialized in the main program.  
But cannot see how/or where in your main code you mark the event that the game is over. This may be key to understanding the issue. 🙂

Also, I played with your code a bit to understand the behavior you want.  
A super simple working version to confirm this is the basic behavior you want to reset the color to the initial red. (?) With a few comments.

```auto
//////////////////////////////////////////////////////////////////////////////
int x = 150;
int y = 150;
int w = 100;
int h = 100;

boolean activated = false; //set to false/off before the mouse position is hovering over the rect

boolean invisible = false; //?? no info on how this fits into your main program
boolean end = false; //?? no info on how this fits into your main program 

color col = color(255, 0, 0);
color black = color(0);

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

  fill(col); // initialize with red
  rect (x, y, w, h);
}

void draw() {

  if (mouseX > x && mouseX < x+w && mouseY > y && mouseY < y+h) {
    activated = true;
  } else {
    activated = false;
  }

  if (activated) {
    fill(black); // change to black after mouse position over rect, stays black until reset(any key is pressed)

    rect (x, y, w, h);
  }
  
  if (keyPressed == true) {
    fill(col);
    rect (x, y, w, h);
  } else {
    fill(0); // need the else statement or reset to red does not work
  }
}

```

Hopefully this is helpful! 🙂

🤓

---

_[View the full topic](https://discourse.processing.org/t/referencing-colour-value-i-defined-in-the-main-project-again-in-class-after-redefining-it-in-class/40308)._
