TFT Menu using drawScreen - Button malfunction

I am having some issues. I'm new to Arduino as well as C++ and have been tinkering with an environmental controller I want to build for my terrarium. I have borrowed some code, most of it from multiple projects throughout the web who have offered their sketches to the public. I have gotten 3 of my 5 relays working and I'm now working on the display TFTLCD since it just came in 5 days ago. It's been 16hrs a day trying to decipher what I'm doing since then.

Basically I'm trying to create a menu page using the drawPage (); syntax... So if the button area is pressed it will pull the "void drawPage() {}" it corresponds to.

Please don't hate on me for being a noob, and not knowing terminology etc.. but it seems like some of my "if" statements aren't working right now, and I'm probably going about this the wrong way entirely, but I've tried 10 different ways and this seems the easiest way to call a page up to me... Is there anything that looks wrong with this code? The top half directing the button/pressed area to the "void drawMenu () {}" works fine, but when I press the button on the home page and it goes to the menu it displays the menu page and immediately reverts back to the "drawHome" page or currentpage = 0. I tried adding another if statement saying basically if there was no pressure to make currentpage == 1 and it worked for getting from home page to menu page but then the home button does not work on the menu page as if it doesn't exist. Like it's only grabbing my "TSPoint p = ts.getPoint();" only checks pressure on the home page. I know my plot points for my buttons aren't exactly right, I've searched but cant figure out how to plot points for a button yet. I've worked on this basically non stop for 4 weeks now. I'm far from finished. I still gotta get the pages to show up, then figure out how to get the settings to be programmed in on those pages so I can change heating, cooling, humidity, lighting and run a fan on my 8 relay board. I am using an Arduino Mega 2560 and will comment back with full code in a bit after I clean it up so I don't get heckled for it. lol

ORIGINAL CODE I TRIED (MENU PAGE IMMEDIATELY LOOPS BACK TO HOME PAGE)

void loop() {

  digitalWrite(13,HIGH);
  TSPoint p = ts.getPoint();
  digitalWrite(13,LOW);

  pinMode(XM, OUTPUT);
  pinMode(YP, OUTPUT);

  if (currentpage == 0)  {

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

        // Check if MENU BUTTON is chosen
        if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
        Serial.print("Menu Selected");

        currentpage = 1;
        delay(10);

        drawMenu();
      }

  } //END CURRENTPAGE 0

 
 if (currentpage == 1)   {
      
      if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

        // Check if Home BUTTON is chosen
        if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
        Serial.print("Home Selected");

        currentpage = 0;
        delay(10);

        drawHome();
      }

  } //END CURRENTPAGE 1

) //END VOID LOOP

CODE WITH FIX I TRIED

void loop() {

  if (p.z > MINPRESSURE && p.z < MAXPRESSURE)  {

        // Check if MENU BUTTON is chosen
        if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
        Serial.print("Menu Selected");

        currentpage = 1;
        delay(10);

        drawMenu();
      }

  } //END CURRENTPAGE 0


 if (currentpage == 1)   {

//ADDED THIS IF STATEMENT AS A FIX, menu page stays active now but home button on menu page doesn't return to home if pressed. 
 
   if (p.z = 0) {

       currentpage == 1;
     
      }  //END OF FIX


      if (p.z > MINPRESSURE && p.z < MAXPRESSURE) {

        // Check if Home BUTTON is chosen
        if (p.x > 850 && p.x < 923 && p.y > 800 && p.y < 900)
        Serial.print("Home Selected");

        currentpage = 0;
        delay(10);

        drawHome();
      }

  } //END CURRENTPAGE 1

) //END VOID LOOP
   if (p.z = 0) {

       currentpage == 1;

STOP RIGHT NOW.

You REALLY, REALLY need to understand, ALL THE WAY DOWN TO YOUR TOES, the differences between the = operator and the == operator. They are NOT interchangeable.

PaulS:

   if (p.z = 0) {

currentpage == 1;



STOP RIGHT NOW.

You REALLY, REALLY need to understand, ALL THE WAY DOWN TO YOUR TOES, the differences between the = operator and the == operator. They are NOT interchangeable.

OK, so I did some research on "=" & "==" and I see your point. I didn't realize there was a difference. As I mentioned I'm new to C++. I see that "=" is basically saying something is = to something else defining what the first something is. ex. NOTHING = SOMETHING , so when I say "I got nothing out of that response." I'm really saying "I got something out of that response." But, when it comes to "==" its not equal to, it registers true or false. So, if the "currentpage == 1" its saying the statement afterwards is true and to do it. If it's not "1" it will return false meaning it won't follow the proceeding event. Have I got a handle on those two operators now? I appreciate you pointing that out. I have fixed the code changing the currentpage == 1; within my code to currentpage = 1; within the "if" statement but it still hasn't fixed the issue. I've been trying to get it to read properly for a couple hours. I would greatly appreciate the assistance!

Have I got a handle on those two operators now?

Yes.

I have fixed the code

I'm not inclined to take your word for the changes you made. I'd be more inclined to look at your revised code.

Got it working completely!