# Custom Game project

**URL:** <https://discourse.processing.org/t/custom-game-project/39707>\
**Category:** Coding Questions\
**Created:** [November 14, 2022, 4:56pm UTC](https://discourse.processing.org/t/custom-game-project/39707 "2022-11-14T16:56:03Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)\
**Post date:** [November 14, 2022, 4:56pm UTC](https://discourse.processing.org/t/custom-game-project/39707/1 "2022-11-14T16:56:03Z")

</div>

Hello everyone once again! I’m having a problem trying to make a game, i have my concept and have gotten some help from my professor but im still coming up with errors.  
The concept of the game is you control a bubble that you need to keep away from a pin floating around. There is more I want to add but for now, I would like help figuring out why my timer won’t work.

```auto
class timer {
  // props
  int startTime;
  int interval;

  //constructor
  Timer(int timeInterval) {
    interval = timeInterval;
  }
  //methods
  void start() {
    startTime = millis();
  }
  
  void complete(){
    
    int elapsedTime = millis() - startTime;
    if (elapsedTime > interval) 
    {
      return true;
    } 
    else {
      return false;
    }//end if
  } 
}//end class

```

I’ve also attached screenshots to everyone who helps can have a visual understanding of what’s going on

 ![Screen Shot 2022-11-14 at 1.02.50 AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/f/dff68ab2632f82021bc058f2ac204f9a919e7d86.jpeg)  
 ![Screen Shot 2022-11-14 at 11.54.16 AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/2/e/2e3e1bfd01d7c266de25bc8c24a6e634282f764c.png)  
 ![Screen Shot 2022-11-14 at 11.54.02 AM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/3X/d/c/dc8c35aff6eaa40eeeab415c6b16b567d26f80bd.jpeg)

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [November 14, 2022, 5:10pm UTC](https://discourse.processing.org/t/custom-game-project/39707/2 "2022-11-14T17:10:28Z")

</div>

The name of the class and constructor must be exactly the same including case so use either

```auto
class timer {
  // props
  int startTime;
  int interval;

  //constructor
  timer(int timeInterval) {
    interval = timeInterval;
  }

```

or

```auto
class Timer {
  // props
  int startTime;
  int interval;

  //constructor
  Timer(int timeInterval) {
    interval = timeInterval;
  }

```

Although both options are correct the second option is preferred because in Java class names are capitalized by convention.

---

<div class="post-metadata">

**Author:** ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)\
**Post date:** [November 14, 2022, 5:39pm UTC](https://discourse.processing.org/t/custom-game-project/39707/3 "2022-11-14T17:39:03Z")

</div>

Wonderful that worked for that problem! my next issue comes with the if statements it’s saying these variables don’t exsits im confused if I need to replace the words with myTimer or something else

```auto
Timer myTimer;

int currentTime;
String s;

void setup() {
  size(1200, 600);
  myTimer = new Timer(1000);
  s ="";
}

void draw() {
  background(200);

  //timer stuff
  if (myTimer.complete()== true){
    if (countdownTime > 0){
    currentTime++;
    countdownTIme--;
    timer.start();
  } 
  }
  
  else {
    fill (255, 0, 0);
    rect(0,0, width, height);
  }// end cdt

  // text stuff
  fill(255);
  textSize(48);
  textAlign(CENTER);
  s= "Current time is" + currentTime;
  s +="Countdown time is " + countdownTime;
  text(s,width/2, height/2);

}Timer myTimer;

int currentTime;
String s;

void setup() {
  size(1200, 600);
  myTimer = new Timer(1000);
  s ="";
}

void draw() {
  background(200);

  //timer stuff
  if (myTimer.complete()== true){
    if (countdownTime > 0){
    currentTime++;
    countdownTIme--;
    timer.start();
  } 
  }
  
  else {
    fill (255, 0, 0);
    rect(0,0, width, height);
  }// end cdt

  // text stuff
  fill(255);
  textSize(48);
  textAlign(CENTER);
  s= "Current time is" + currentTime;
  s +="Countdown time is " + countdownTime;
  text(s,width/2, height/2);

```

}

---

<div class="post-metadata">

**Author:** ![quark](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/quark/32/26_2.png) [@quark](https://discourse.processing.org/u/quark)\
**Post date:** [November 14, 2022, 5:44pm UTC](https://discourse.processing.org/t/custom-game-project/39707/4 "2022-11-14T17:44:16Z")

</div>

You need to correct the code above you seem to have the sketch coded duplicated. Also you need to include the code for your timer class.

---

<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:** [November 14, 2022, 6:20pm UTC](https://discourse.processing.org/t/custom-game-project/39707/5 "2022-11-14T18:20:02Z")

</div>

Please post your entire code. In one go.

Please not as images but as text.

Thank you.

---

<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:** [November 14, 2022, 6:21pm UTC](https://discourse.processing.org/t/custom-game-project/39707/6 "2022-11-14T18:21:35Z")

</div>

> [@JHProcess](#):
>
> `countdownTIme`

processing is case sensitive, so the typo here is relevant, use a small i

---

<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:** [November 14, 2022, 6:22pm UTC](https://discourse.processing.org/t/custom-game-project/39707/7 "2022-11-14T18:22:26Z")

</div>

> [@JHProcess](#):
>
> `timer.start();`

Won’t work, you need myTimer.start() - the name of the object

---

<div class="post-metadata">

**Author:** ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)\
**Post date:** [November 14, 2022, 6:30pm UTC](https://discourse.processing.org/t/custom-game-project/39707/8 "2022-11-14T18:30:29Z")

</div>

Fixed that issue now saying it missing a “;” but i have one implemented there

```auto
class myTimer;

int currentTime;
String s;

void setup() {
  size(1200, 600);
  myTimer = new myTimer(1000);
  s ="";
}

void draw() {
  background(200);

  //timer stuff
  if (timer.complete()== true){
    if (countdownTime > 0){
    currentTime++;
    countdownTIme--;
    mytimer.start();
  } 
  }
  
  else {
    fill (255, 0, 0);
    rect(0,0, width, height);
  }// end cdt

  // text stuff
  fill(255);
  textSize(48);
  textAlign(CENTER);
  s= "Current time is" + currentTime;
  s +="Countdown time is " + countdownTime;
  text(s,width/2, height/2);

}

```

---

<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:** [November 14, 2022, 6:45pm UTC](https://discourse.processing.org/t/custom-game-project/39707/9 "2022-11-14T18:45:12Z")

</div>

Are you still using the class?

---

<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:** [November 14, 2022, 6:47pm UTC](https://discourse.processing.org/t/custom-game-project/39707/10 "2022-11-14T18:47:41Z")

</div>

> [@JHProcess](#):
>
> `class myTimer;`

That won’t work. (the keyword `class` is only used where you define the class)

When your class is named `Timer` the line to use the class is:

`Timer myTimer = new Timer();`

It’s convention to have a class name (`Timer`) start with a Capital Letter. The object derived from the class is with a small letter: `myTimer`

To use a variable or function of the class, say `myTimer.start();` etc., using

- the object name and
- a dot . and
- the function name / variable name

you don’t use Timer there, you don’t the content of the class directly, only as myTimer.something…

---

<div class="post-metadata">

**Author:** ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)\
**Post date:** [November 14, 2022, 6:56pm UTC](https://discourse.processing.org/t/custom-game-project/39707/11 "2022-11-14T18:56:34Z")

</div>

Many errors just occurred saying the class “timer” doesnt exists and is suggesting a java import timer but that then makes even more issues

```auto
Timer myTimer = new Timer();

int currentTime;
String s;

void setup() {
  size(1200, 600);
  myTimer = new myTimer(1000);
  s ="";
}

void draw() {
  background(200);

  //timer stuff
  if (timer.complete()== true){
    if (countdownTime > 0){
    currentTime++;
    countdownTIme--;
    mytimer.start();
  } 
  }
  
  else {
    fill (255, 0, 0);
    rect(0,0, width, height);
  }// end cdt

  // text stuff
  fill(255);
  textSize(48);
  textAlign(CENTER);
  s= "Current time is" + currentTime;
  s +="Countdown time is " + countdownTime;
  text(s,width/2, height/2);

}

```

```auto

```

---

<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:** [November 14, 2022, 7:28pm UTC](https://discourse.processing.org/t/custom-game-project/39707/12 "2022-11-14T19:28:08Z")

</div>

You need to copy paste the class at the end

Nice tutorial [Objects / Processing.org](https://processing.org/tutorials/objects)

---

<div class="post-metadata">

**Author:** ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)\
**Post date:** [November 15, 2022, 1:03am UTC](https://discourse.processing.org/t/custom-game-project/39707/13 "2022-11-15T01:03:09Z")

</div>

i apologize for not responding for so long I was contemplating restarting from the ground up and decide to do that. I’m trying to figure out why “millis” won’t work

```auto
class myTimer {
  // props
  int startTime;
  int interval;
  
  //constructor
  myTimer(int timeInterval) {
    interval = timeInterval;
  }
  //methods
  void start() {
    startTime = millis();
  }
  
  boolean complete(){
    
    int elapsedTime = millis() - startTime;
    if (elapsedTime > interval) 
    {
      return true;
    } 
    else {
      return false;
    }//end if
  } 
}//end class

```

---

<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:** [November 15, 2022, 1:51am UTC](https://discourse.processing.org/t/custom-game-project/39707/14 "2022-11-15T01:51:22Z")

</div>

The class is called Timer …

---

<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:** [November 15, 2022, 1:52am UTC](https://discourse.processing.org/t/custom-game-project/39707/15 "2022-11-15T01:52:25Z")

</div>

As I said, post your entire code, class and the rest…

---

<div class="post-metadata">

**Author:** ![JHProcess](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@JHProcess](https://discourse.processing.org/u/JHProcess)\
**Post date:** [November 15, 2022, 2:35am UTC](https://discourse.processing.org/t/custom-game-project/39707/16 "2022-11-15T02:35:40Z")

</div>

sorry was driving but here is the class code and the button code

```auto

```

```auto

```

```auto

```

```auto
class myTimer {
  // props
  int startTime;
  int interval;
  
  //constructor
  myTimer(int timeInterval) {
    interval = timeInterval;
  }
  //methods
  void start() {
    startTime = millis();
  }

```

```auto
boolean complete(){

```

```
int elapsedTime = millis() - startTime;
if (elapsedTime > interval) 
{
  return true;
} 
else {
  return false;
}//end if

```

}  
}//end class

```auto

```

```auto
class Button
{
  PVector Pos= new PVector(0, 0);
  float Width = 0;
  float Height = 0;
  color Color;
  String Text;
  Boolean Pressed = false;
  Boolean Clicked = false;
  // constructor to create a button
  Button(int x, int y, int w, int h, String t, int r, int g, int b)
  {
    Pos.x = x;
    Pos.y = y;
    Width = w;
    Height = h;
    Color = color(r, g, b);
    Text= t;
  }
  void update() //must be placed in void draw() to work
  {
    if (mousePressed==true &&mouseButton == LEFT && Pressed== false)
    {
      Pressed = true;
      if (mouseX>=Pos.x && mouseX <= Pos.x+Width && mouseY >= Pos.y && mouseY <= Pos.y+Height)
      {
        Clicked = true;
      } else
      {
        Clicked = false;
      }
      if (mousePressed !=true)
      {
        Pressed = false;
      }
    }
  }
    void render()// must be placed void draw to render the button to the screen
    {
      fill(Color);
      rect(Pos.x,Pos.y,Width,Height);
      
      
      fill(0);
      
      textAlign(CENTER,CENTER);
      text(Text,Pos.x+(Width/2),Pos.y+(Height/2));
      
    }
    //boolean isClicked()// Use this in a if statement to check if the button has clicked
    //{
    //return Clicked;

```

```auto
    
  }

```

```auto

```

---

<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:** [November 15, 2022, 3:47am UTC](https://discourse.processing.org/t/custom-game-project/39707/17 "2022-11-15T03:47:31Z")

</div>

> [@JHProcess](#):
>
> `Timer myTimer = new Timer();`

This line implies that your class is named Timer,  
not myTimer

Read the tutorial I posted above
