# Unexpected token void, how to fix?

**URL:** <https://discourse.processing.org/t/unexpected-token-void-how-to-fix/6614>\
**Category:** Beginners\
**Created:** [December 14, 2018, 8:40pm UTC](https://discourse.processing.org/t/unexpected-token-void-how-to-fix/6614 "2018-12-14T20:40:29Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mister\_Loinus](https://avatars.discourse-cdn.com/v4/letter/m/c5a1d2/32.png) [@Mister\_Loinus](https://discourse.processing.org/u/Mister_Loinus)\
**Post date:** [December 14, 2018, 8:40pm UTC](https://discourse.processing.org/t/unexpected-token-void-how-to-fix/6614/1 "2018-12-14T20:40:29Z")

</div>

Idk why it’s giving me this unexpected error, can anyone help? quite new to programming :)) Thanks!

```auto
int left,right,up,down;
boolean goLeft,goRight,goUp,goDown;
int dudeX=1800,dudeY=1000, speed=1;

int chestX=1800,chestY=1000;

void setup(){
  noStroke();
  fullScreen();
  //replace with dungeon floor thingy
  background(50,50,50);
}

void draw (){
  if(dudeX + 20 >= 100)goLeft = false; // r1 right edge past r2 left
  if(dudeX <= 100 + 100)goRight = false; // r1 left edge past r2 right
  if(dudeY + 20 >= 150)goDown = false; // r1 top edge past r2 bottom
  if(dudeY <= 150 + 100)goUp = false; // r1 bottom edge past r2 top
  
  if(goUp)dudeY -= up * speed;
  if(goDown)dudeY += down * speed; 
  if(goLeft)dudeX -= left * speed;
  if(goRight)dudeX += right * speed;
  
  noCursor();
clear();
rect(chest,chestX,chestY,50,50);
rect(dude,dudeX,dudeY,100,100);
//Movement and exit
void keyPressed(){
  if (key == ESC){
   exit(); 
  }
  
  if (key == 'a' || key == 'A') {
    left = 1;
  }
  if (key == 'd' || key == 'D') {
    right = 1;
  }
  if (key == 'w' || key == 'W') {
    up = 1;
  }
  if (key == 's' || key == 'S') {
    down = 1;
  }
}
void keyReleased(){
  if (key == 'a' || key == 'A') {
    left = 0;
  }
  if (key == 'd' || key == 'D') {
    right = 0;
  }
  if (key == 'w' || key=='W') {
    up = 0;
  }
  if (key == 's' || key == 'S') {
    down = 0;
  }
}

```

---

<div class="post-metadata">

**Author:** ![jb4x](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jb4x/32/789_2.png) [@jb4x](https://discourse.processing.org/u/jb4x)\
**Post date:** [December 14, 2018, 8:46pm UTC](https://discourse.processing.org/t/unexpected-token-void-how-to-fix/6614/2 "2018-12-14T20:46:09Z")

</div>

Hi,

The error you get is usually because you forgot a bracket or a semicolon.

When in processing IDE, hit `ctrl+t` to auto format. It is then easier to find those kind of mistakes. In your case you forgot a closing curly bracket before the `keyPressed()` function.

Also your `rect()` function are wrong.

```auto
int left, right, up, down;
boolean goLeft, goRight, goUp, goDown;
int dudeX=1800, dudeY=1000, speed=1;

int chestX=1800, chestY=1000;

void setup() {
  noStroke();
  fullScreen();
  //replace with dungeon floor thingy
  background(50, 50, 50);
}

void draw () {
  if (dudeX + 20 >= 100)goLeft = false; // r1 right edge past r2 left
  if (dudeX <= 100 + 100)goRight = false; // r1 left edge past r2 right
  if (dudeY + 20 >= 150)goDown = false; // r1 top edge past r2 bottom
  if (dudeY <= 150 + 100)goUp = false; // r1 bottom edge past r2 top

  if (goUp)dudeY -= up * speed;
  if (goDown)dudeY += down * speed;
  if (goLeft)dudeX -= left * speed;
  if (goRight)dudeX += right * speed;

  noCursor();
  clear();
  rect( chestX, chestY, 50, 50);
  rect( dudeX, dudeY, 100, 100);
}
//Movement and exit
void keyPressed() {
  if (key == ESC) {
    exit();
  }

  if (key == 'a' || key == 'A') {
    left = 1;
  }
  if (key == 'd' || key == 'D') {
    right = 1;
  }
  if (key == 'w' || key == 'W') {
    up = 1;
  }
  if (key == 's' || key == 'S') {
    down = 1;
  }
}
void keyReleased() {
  if (key == 'a' || key == 'A') {
    left = 0;
  }
  if (key == 'd' || key == 'D') {
    right = 0;
  }
  if (key == 'w' || key=='W') {
    up = 0;
  }
  if (key == 's' || key == 'S') {
    down = 0;
  }
}

```

PS : Please edit your last post and format the code by clicking this icon: `</>`
