Translate causing error

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?

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

  }
}

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 :heart_eyes:

1 Like

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

in how many places did you add the ; ?

i see its missing in 11 places

I did all of them.

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

here is a little list:

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

Reference:
Variables that are declared with let will have block-scope. This means that the variable only exists within the 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 :slight_smile:

  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 :slight_smile:
But maybe the others are interesting to you too…

----------- now you do :grin:

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

i am sad now.

thanks tho @Hyperion65