# Back button not working in processing program

**URL:** <https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823>\
**Category:** Processing.py\
**Created:** [November 30, 2020, 5:46am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823 "2020-11-30T05:46:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)\
**Post date:** [November 30, 2020, 5:46am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823/1 "2020-11-30T05:46:20Z")

</div>

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:

```auto
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()

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 30, 2020, 6:30am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823/2 "2020-11-30T06:30:37Z")

</div>

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’ –

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

---

<div class="post-metadata">

**Author:** ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)\
**Post date:** [November 30, 2020, 6:39am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823/3 "2020-11-30T06:39:58Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 30, 2020, 7:23am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823/4 "2020-11-30T07:23:32Z")

</div>

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](https://processing.org/reference/libraries/), but I couldn’t comment on any of those.

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

---

<div class="post-metadata">

**Author:** ![millionish](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@millionish](https://discourse.processing.org/u/millionish)\
**Post date:** [November 30, 2020, 7:43am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823/5 "2020-11-30T07:43:35Z")

</div>

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

```auto
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

```

---

<div class="post-metadata">

**Author:** ![tabreturn](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/tabreturn/32/3697_2.png) [@tabreturn](https://discourse.processing.org/u/tabreturn)\
**Post date:** [November 30, 2020, 10:10am UTC](https://discourse.processing.org/t/back-button-not-working-in-processing-program/25823/6 "2020-11-30T10:10:10Z")

</div>

⚠ your last reply is a double post

> [@Move the box with keyboard and mouse](https://discourse.processing.org/t/move-the-box-with-keyboard-and-mouse/25824):
>
> 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
