# Translate causing error

**URL:** <https://discourse.processing.org/t/translate-causing-error/23833>\
**Category:** Libraries\
**Created:** [September 13, 2020, 10:08am UTC](https://discourse.processing.org/t/translate-causing-error/23833 "2020-09-13T10:08:58Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![SamuelCobb](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@SamuelCobb](https://discourse.processing.org/u/SamuelCobb)\
**Post date:** [September 13, 2020, 10:08am UTC](https://discourse.processing.org/t/translate-causing-error/23833/1 "2020-09-13T10:08:58Z")

</div>

hey guys, I have a very short piece of code which I am trying to write, but it seems that the translate function is causing some sort of error. anyone know why?

```auto
function setup() {
  cnv = createCanvas(400, 400, WEBGL);
  buffer = createGraphics(width, height, WEBGL)
  cube = new Cube(5, 50, 255, 0,0,0)
  cam = createEasyCam();
}

function draw() {
  background(220);
  cube.show()
}

function mouseClicked(){
  console.log(buffer.get(mouseX, mouseY));
}

class Cube{
  constructor(id, size, c, x, y, z){
    this.id = id;
    this.size = size;
    this.c = c;
    this.x = x;
    this.y = y;
    this.z = z;
  }
  
  show(){
    push()
    translate(this.x, this,y, this.z)
    fill(this.c)
    box(this.size)
    buffer.fill(this.id)
    buffer.box(this.size)
    translate(-this.x, -this.y, -this.z)
    pop()

  }
}

```

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 13, 2020, 12:46pm UTC](https://discourse.processing.org/t/translate-causing-error/23833/2 "2020-09-13T12:46:05Z")

</div>

computers are stupid (or clever). it’s like being in a relationship…

they only love you when you say the “exact” words they expect from you. otherwise they pout and refuse to even talk to you or do what you ask them…

simply use `;` after every statement.

you will see, your code will say 😍

---

<div class="post-metadata">

**Author:** ![SamuelCobb](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@SamuelCobb](https://discourse.processing.org/u/SamuelCobb)\
**Post date:** [September 14, 2020, 9:34am UTC](https://discourse.processing.org/t/translate-causing-error/23833/3 "2020-09-14T09:34:25Z")

</div>

no, doesn’t work

anyway, p5 is a pretty loosely typed language so there can be some exceptions.

Even when added, it does the same error

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 14, 2020, 11:32am UTC](https://discourse.processing.org/t/translate-causing-error/23833/4 "2020-09-14T11:32:19Z")

</div>

in how many places did you add the **;**?

i see its missing in 11 places

---

<div class="post-metadata">

**Author:** ![SamuelCobb](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@SamuelCobb](https://discourse.processing.org/u/SamuelCobb)\
**Post date:** [September 14, 2020, 12:24pm UTC](https://discourse.processing.org/t/translate-causing-error/23833/5 "2020-09-14T12:24:50Z")

</div>

I did all of them.

For some reason it didn’t work. I think it is for another reason which I don’t know.

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 14, 2020, 12:29pm UTC](https://discourse.processing.org/t/translate-causing-error/23833/6 "2020-09-14T12:29:07Z")

</div>

here is a little list:

1. I think you should still declare your variables outside setup():

> Reference:  
> Variables that are declared with [let](https://p5js.org/reference/#/p5/let) will have block-scope. This means that the variable only exists within the [block](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/block) that it is created within.

let buffer;  
let cube;

1. p5js may be sloppy, but im sure not mixing the way you formulate things is a good idea, so ending a code line with ; is good 🙂

2. im not sure why you want to use a variable for createCanvas → “cnv” = createCanvas…

3. you seem to have a typo at: translate(this.x, **this, y** , this.z);

should be ‘this.y’. **(that’s where you’re code actually stops in my tests)**

1. you do not have to translate things “back”. that is what push() and pop() is actually for.  
so no need to say: translate(-this.x,…)

2. if you draw into a PGraphics, you need to display that too, e.g. in draw()  
` image(buffer,-width/2,-height/2);`

So, actually, only items 4 and 6 on my list might be considered errors in your code 🙂  
But maybe the others are interesting to you too…

---

<div class="post-metadata">

**Author:** ![Hyperion65](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hyperion65/32/10569_2.png) [@Hyperion65](https://discourse.processing.org/u/Hyperion65)\
**Post date:** [September 14, 2020, 12:31pm UTC](https://discourse.processing.org/t/translate-causing-error/23833/7 "2020-09-14T12:31:25Z")

</div>

> [@SamuelCobb](#):
>
> I think it is for another reason which I don’t know.

----------- now you do 😁

---

<div class="post-metadata">

**Author:** ![SamuelCobb](https://avatars.discourse-cdn.com/v4/letter/s/73ab20/32.png) [@SamuelCobb](https://discourse.processing.org/u/SamuelCobb)\
**Post date:** [September 14, 2020, 11:52pm UTC](https://discourse.processing.org/t/translate-causing-error/23833/8 "2020-09-14T23:52:12Z")

</div>

it was just the this.y :((((((((

i am sad now.

thanks tho @Hyperion65
