# Game issues for christmas

**URL:** <https://discourse.processing.org/t/game-issues-for-christmas/14780>\
**Category:** Coding Questions\
**Created:** [October 18, 2019, 3:30pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780 "2019-10-18T15:30:40Z")\
**Posts on this page:** 20\
**Page:** 3

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 20, 2019, 3:06am UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/41 "2019-10-20T03:06:37Z")

</div>

hi @Mike,

please not get confused when you get hammered from two sides,  
but @Chrisir and me work IN SHIFT ( i am from thailand )

also he try to help about the STATE / SCREEN thinking  
( and why a screen = 1 is better as a screenone = true )

while i try a crash course about

- variables
- functions ( methods )
- arrays
- class
- array of class

YES we are on the CLASS level now  
go back to my above post and reread

[Need help with game issues for christmas](https://discourse.processing.org/t/need-help-with-game-issues-for-christmas/14780/25) ,

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 3:32am UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/42 "2019-10-20T03:32:36Z")

</div>

I’m lost… Should I be redoing the whole game or try to incorporate the States?

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 20, 2019, 3:46am UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/43 "2019-10-20T03:46:35Z")

</div>

actually NO ( to both ) but that is up to you.

-a- you can study my 3 button code version to get a idea,  
( but possibly for your next project )

-b- you should build up the STATE structure in a own little learn project first,  
but already structured for all the operational logic of your project,  
while the screen shown could be two simple rectangles ( or already buttons ).

-c- if you copy later in your original screen pages

or my “array function” or “array class function” pages  
depends on if you understand them.

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 4:25am UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/44 "2019-10-20T04:25:25Z")

</div>

I don’t really… Not yet anyway haha

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 20, 2019, 5:00am UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/45 "2019-10-20T05:00:57Z")

</div>

no problem,  
so you work on

> -b-

and show/link it please, so we can follow you  
remember that you need to “know”  
not only the STATE / SCREEN to show ( from draw )  
also what the question was and what the answer was!  
( for develop show that on the STATE screen )

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 4:09pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/46 "2019-10-20T16:09:32Z")

</div>

ok i think i finally got it working with my original code. my problem was when i was setting the mousepressed function to go from any of the answer screens back to the board i was having the board buttons working on the answer screen. It seems that because i was setting the board to true in the same function i was trying to change the answer screen to off it was allowing the board buttons to be active during that mouse press. I changed over to adding in states starting with 0 for the title screen, 1 for the board, 2 for round 2, 4 for questions, and 5 for answers. Now when i’m doing the mouse pressed to i have added i’m mouseover so that the answer screen has only one rectangle location that allows it to go back to the board. once i’m done with all the question screens and answer screens ill post the code again. At least now there is a light at the end of the tunnel and it seems i’m going to get this done haha. I’m gonna start learning more about arrays and classes after this so my code doesn’t have to be 4000+ lines haha

---

<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:** [October 20, 2019, 4:44pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/47 "2019-10-20T16:44:49Z")

</div>

Well done and congratulations!

I think you can keep your version and work with it.

But let me explain what I would do the next time you start a big project like this please.

At the moment you have a lot of lines that are very similar where you check the cells of the grid.

Also you have positions in the text statements where you show the cells and where you check the mouse position against it. These are redundant position information.

When writing a program you would make a data structure (array of class/objects) to have the information in one place.

Then you don’t need a lot of similar lines with if but can for loop over the array to access all cells in the grid.

I and kll tried to demonstrate a bit of that in my post.

Chrisir

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 5:36pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/48 "2019-10-20T17:36:02Z")

</div>

yea it seems i got comfortable with a few functions and ran with that haha but im gonna learn more and get better.  
although i still have a problem, the same problem. i fixed almost everything else:  
[https://editor.p5js.org/mcfiorino624/sketches/Z6yzpveeF](https://editor.p5js.org/mcfiorino624/sketches/Z6yzpveeF)  
so whether your in round 1 or round 2 and you go to click the category 3 800 point question it is still clicking some answer button it shouldn’t. how do i watch the console to see what is happening?  
its only that one button on both round 1 and 2. i checked the mousePressed for both of the rounds and all the questions and they are all the same so i dont know what the issue is.

---

<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:** [October 20, 2019, 6:44pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/49 "2019-10-20T18:44:29Z")

</div>

I got a suspicion here

I’m not sure which lines we are talking about

Let’s say

```auto
  if (mouseX > 300 && mouseX < 380 && mouseY > 460 && mouseY < 540 && (state == 1)) {
    state = 4;
    q28 = true;
  }

```

OK, just an idea.

Let’s say you want to have only one reaction per mouse click and not two:

Go to the if-clause for _“category 3 800 point question”_

```auto
  if (mouseX > 300 && mouseX < 380 && mouseY > 460 && mouseY < 540 && (state == 1)) {
    state = 4;
    q28 = true;
    return; // <------ ENTER THIS line here 
  }

```

Thank you.

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 6:54pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/50 "2019-10-20T18:54:24Z")

</div>

So what is adding return doing? And I’ll add it when I get home and see what it does?

---

<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:** [October 20, 2019, 6:57pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/51 "2019-10-20T18:57:58Z")

</div>

my theory is that : you change state in this if clause.

Therefore when we reach the other  
if clause state is already changed and therefore  
the 2nd condition is also true.

(our idea was that state would stop the 2nd if from executing but this won’t work now (it’s because how your code is, never mind))

The `return` command immediately leaves the whole mousePressed function the hard way, so the 2nd if-clause can’t be reached. It will be reached next time you click the mouse though.

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 8:13pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/52 "2019-10-20T20:13:04Z")

</div>

OMG!!! it works hahaha. I definitely need to clean up so much of this code but it is all functioning without any glitches. Thank you guys for taking the time to deal with my vast amounts of noob haha. I cant wait to start a second project and learn how to have an array with player names and maybe a point system that actuallly keeps track of points for each person.

---

<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:** [October 20, 2019, 8:34pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/53 "2019-10-20T20:34:04Z")

</div>

Actually, how are you planning this exactly?

You mentioned skype.

So you are planning to run this on your computer and the others are just having skype without seeing it on the computer? Or do they see it on the computer? Because I am not sure if you can run it and everybody sees your screen. You would be the only one to enter stuff in this scenario. You would enter by mouse. You would be the game master then.

There are ways to program multiplayer games in processing but that’s over my head.

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 8:49pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/54 "2019-10-20T20:49:46Z")

</div>

yea this time around im just gonna be the master and do everything, but next program i was thinking of making something where i can send them the link and they can play on their own by entering there name and playing locally not multiplayer.

---

<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:** [October 20, 2019, 8:52pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/55 "2019-10-20T20:52:29Z")

</div>

> [@Mike](#):
>
> im just gonna be the master and do everything

but how can they see your screen?

Or can skype just show them your screen?

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 9:01pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/56 "2019-10-20T21:01:19Z")

</div>

skype has a screen share option.  
so does discord

---

<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:** [October 20, 2019, 9:01pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/57 "2019-10-20T21:01:35Z")

</div>

In my opinion you could rewrite your mousePressed like this:

```auto

function mousePressed() {

  if (state==0) {
    mousePressedForState0();
  }
  //----
  else if (state==1) {
    mousePressedForState1();
  }
  //----
  else if (state==2) {
    mousePressedForState2();
  }
  //----
  else if (state==3) {
    mousePressedForState3();
  }
  //----
  else if (state==4) {
    mousePressedForState4();
  }
  //----
  else if (state==5) {
    mousePressedForState5();
  } else {
    // error
    println ("Error"); 
    exit(); 
    return;
  }//else 
  //
}//function

```

Then make those functions and put what you have in mousePressed now inside those functions (the stuff for state 0 in the appropriate function mousePressedForState0() and so on).

Then your code is better readable since it’s in nice modules.

Same goes for function draw() by the way

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 20, 2019, 9:03pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/58 "2019-10-20T21:03:39Z")

</div>

yea that looks much cleaner.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 21, 2019, 12:10pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/59 "2019-10-21T12:10:40Z")

</div>

want try about modules? still want to follow?  
reread above,  
i gave you already  
-1- a button function  
-2- a array of buttons  
-3- a array of class button

* * *

now add:  
-4- a modular program structure for this game  
-5- the question/answers/goodanswer/ thing is to be considered as DATA  
not as text inside a CODE,  
so in a extra 31 line CSV file read as table object,  
what sure can compete with arrays once you dig into its handling.

---

<div class="post-metadata">

**Author:** ![Mike](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mike](https://discourse.processing.org/u/Mike)\
**Post date:** [October 21, 2019, 1:55pm UTC](https://discourse.processing.org/t/game-issues-for-christmas/14780/60 "2019-10-21T13:55:14Z")

</div>

yea i saved your examples so i can fool around with them and rewrite them on my own. i have been looking up how to modularize my program using some file.js and referencing it as a source in index.html. ill get there it just may take a while to figure all of this out, but hey my sloppy program works hahaha

[Previous page](https://discourse.processing.org/t/game-issues-for-christmas/14780.md?page=2)

[Next page](https://discourse.processing.org/t/game-issues-for-christmas/14780.md?page=4)
