Game issues for christmas

Not the bottoms but the questions and answers I need separate states for all of those don’t I?? If there is 30 questions in round 1 don’t I need 30 states for that

??

You need one variable state. Since it’s of type integer it can be 0,1,2…

Now 0 just says the entire program is in screen for the grid.

1 for an answer.

The buttons are another thing. I‘d use an array for the buttons of the grid. See my example

No. (Or I don’t get it)

Yea that makes sense but if I’m putting 30 questions in the round 1 of the game if you click a button on the main board it should go to a screen with the question. And then with another button press reveal the answer on another screen… So if I have 30 questions and answers that will be one state each… That’s alot of States. Or it can reveal the answer on the question screen I don’t care but that’s still 30 + States.

when you look at my example:

There is a class Button which contains the cover (800 $ for hidden card) and the answer and the question. We have an array of that class.

Now you need only one state but you display the text that is stored in the current cell of the grid

Hm.

when you want to stick with your approach: It’s a good program.

just add the state variable where you check the mouse

I’ll see tonight if I can clean up mine and I’ll resend it and see if you guys think it’s functional or If you think I need to scrap it

1 Like

stick with your approach: It’s a good program.

just add the state variable where you check the mouse

set the state variable

  • to 0 when you enter the grid

  • to 1 when you show an answer

So especially in these if clause you want to add

  • … && state==0 in the if clause of the question

  • and … && state==1 in the if clause of the show answer button

so the program can distinguish between the two situations and the buttons are NOT evaluated both

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 ,

1 Like

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

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.

I don’t really… Not yet anyway haha

1 Like

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 )

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

2 Likes

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

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
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.

I got a suspicion here

I’m not sure which lines we are talking about

Let’s say

  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”

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

Thank you.

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

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.

1 Like

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.

1 Like

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.