Back button not working in processing program

Hello, I want to implement a back button functionality in my program. When I click on the start button, it takes it to another screen but when I click on the back button, nothing happens.
Below is the simplified code:

def go():
    fill(255)
    rect(450,320,100,100)
    fill(0)
    textSize(18)
    text("BACK",470,380)

def setup():
    size(1000,800)
    
def draw():
    fill(255)
    rect(450,320,100,100)
    fill(0)
    textSize(18)
    text("START",470,380)
    
    if(mousePressed and mouseX>450 and mouseX<550 and mouseY>320 and mouseY<420):
        noLoop()
        go()

I would suggest structuring this differently. Something that can accommodate additional menus, screens, and button layouts (should you choose to add more).

Here, I’m using a state variable to manage the ‘screens’ –

state = 'start'

def setup():
    size(1000, 800)

def draw():
    background(0)
    textSize(18)

    if state == 'start':
        # code for drawing on the START screen
        fill(255)
        square(450, 320, 100)
        fill(0)
        text('START', 470, 380)
        
    elif state == 'back':
        # code for drawing on the BACK screen
        fill(255)
        square(450, 500, 100)
        fill(0)
        text('BACK', 475, 560)


def mouseClicked(e):
    global state
        
    if state == 'start':
        # mouse events for the START screen
        if e.x > 450 and e.x < 550 and e.y > 320 and e.y < 420:
            state = 'back'

    elif state == 'back':
        # mouse events for the BACK screen
        if e.x > 450 and e.x < 550 and e.y > 500 and e.y < 600:
            state = 'start'

There are other ways to approach this, but this is the simplest example I could devise.

Thank you it worked! Btw I’m making a game and it’s been really challenging. Is there any direct way I could contact you and take your help?

Developing games in Processing can be challenging – you don’t get all of the features a game engine/library would typically provide. (Vanilla) Processing can handle rendering and input fine, but you’ll have to develop or plug-in anything else you need (physics, GUI components, etc.). There are some Processing game libraries, but I couldn’t comment on any of those.

You can click on any user profile image to send a private message.

Thanks! Could you help me out with this one too please?

I want to move the box using W,A,S,D keys and rotate the box in mouse direction (even while moving). Below is the code I’ve written but it isn’t working properly (haven’t yet implemented the mouse functionality).

x = 100
y = 100

def setup():
    size(1500,850)
    
def draw():
    rect(x,y,100,100)

def keyPressed():
    global x, y
    if key == 'w':
        y-=7
    elif key == 'd':
        x+=7
    elif key == 'a':
        x-=7
    else:
        y+=7

:warning: your last reply is a double post