# Error unexpected token: void

**URL:** <https://discourse.processing.org/t/error-unexpected-token-void/14662>\
**Category:** Beginners\
**Created:** [October 13, 2019, 4:47pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662 "2019-10-13T16:47:21Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![MrRex](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@MrRex](https://discourse.processing.org/u/MrRex)\
**Post date:** [October 13, 2019, 4:47pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/1 "2019-10-13T16:47:21Z")

</div>

Hello, I’m trying to learn processing but I have an error with my code. Here is my code :

```auto
void step() {
  float x;
  float y;
  float r = random(1);
  
  if (r < 0.4) {
    x++;
  } else if (r < 0.6) {
    x--;
  } else if (r < 0.8) {
    y++;
  } else { 
    y--;
  }
}

```

My error :  
“The local variable x may not have been initialized”

Thank you for helping me !

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 13, 2019, 4:48pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/2 "2019-10-13T16:48:57Z")

</div>

just say float x=0 ; in the line you already have

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 13, 2019, 4:52pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/3 "2019-10-13T16:52:24Z")

</div>

Is this your entire sketch by the way?

The function step wouldn’t run on its own.

You should have a function setup and draw as well. Call step() from draw().

Please look on the website tutorials section, first three text tutorials

---

<div class="post-metadata">

**Author:** ![MrRex](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@MrRex](https://discourse.processing.org/u/MrRex)\
**Post date:** [October 13, 2019, 5:34pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/4 "2019-10-13T17:34:06Z")

</div>

It’s not my entire sketch. I’m learning with Daniel Shiffman’s book.

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 14, 2019, 4:26am UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/5 "2019-10-14T04:26:16Z")

</div>

hi,  
-a- please format your code using the `</> Preformatted text` button

-b- also post code as short as possible just to show your problem  
but complete as in we can copy / paste it into the PDE and it runs…

* * *

a running version would be

> one cycle

```auto
void setup() {
  step();
}

float x;
float y;

void step() {
  float r = random(1);
  print("r "+nf(r,0,2)+" x "+x+" y "+y);
  if (r < 0.4) x++;
  else if (r < 0.6) x--;
  else if (r < 0.8) y++;
  else if (r > 0.8) y--;
  println(" now: x "+x+" y "+y);
}

```

> or conti

```auto
void setup() {}
void draw() {
  step();
}

float x;
float y;

void step() {
  float r = random(1);
  print("r "+nf(r,0,2)+" x "+x+" y "+y);
  if (r < 0.4) x++;
  else if (r < 0.6) x--;
  else if (r < 0.8) y++;
  else if (r > 0.8) y--;
  println(" now: x "+x+" y "+y);
}

```

---

<div class="post-metadata">

**Author:** ![MrRex](https://avatars.discourse-cdn.com/v4/letter/m/ba8739/32.png) [@MrRex](https://discourse.processing.org/u/MrRex)\
**Post date:** [October 14, 2019, 4:04pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/6 "2019-10-14T16:04:30Z")

</div>

Can you more explain the code, please ? What’s the difference between “print” and “println” ?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [October 14, 2019, 4:36pm UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/7 "2019-10-14T16:36:20Z")

</div>

println makes a new line / line break after the text, print doesn’t. It stays in the same line

---

<div class="post-metadata">

**Author:** ![Waboqueox](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/waboqueox/32/5643_2.png) [@Waboqueox](https://discourse.processing.org/u/Waboqueox)\
**Post date:** [October 15, 2019, 7:31am UTC](https://discourse.processing.org/t/error-unexpected-token-void/14662/8 "2019-10-15T07:31:53Z")

</div>

With a small adjustment we can see it more graphic 😛

```auto
PVector walker;

void setup() {size(displayWidth,displayHeight);}
void draw() {
  walker = step();
  fill(random(255),120);
  translate(width/2,height/2);
  ellipse(walker.x,walker.y,10,10);
}

float x;
float y;

PVector step() {
  float r = random(1);
  print("r "+nf(r,0,2)+" x "+x+" y "+y);
  if (r < 0.4) x++;
  else if (r < 0.6) x--;
  else if (r < 0.8) y++;
  else if (r > 0.8) y--;
  println(" now: x "+x+" y "+y);
  return new PVector(x,y);
}

```
