Solving an Unexpected Identifier

Greetings!
I’m trying to create a class to draw a bezier curve but seeing ‘unexpected identifier’ error which doesn’t make sense to me : http://tiny.cc/xy7sbz

https://editor.p5js.org/VMK/sketches/D-GpdoGiM

Any help would be highly appreciated, thank you!

var activitesCurve = function(bzCurve) {
  bzCurve.setup = function() {
    var run = [25, 50, 60, 70];
    var walk = [15, 75, 80, 40];
    bzCurve = new BzCurve();
  }
  bzCurve.draw = function() {
    bzCurve.show();
    class BzCurve {
      constructor() {
        this.stroke = (239, 31, 193);
        this.margin = 50;
        this.height = bzCurve.windowHeight;
        this.arr = run;
        this.maxLength = run.length;
        this.pointGap = position;
      }
      show() {
        bezierCurve.stroke(this.stroke);
        bezierCurve.beginShape();
        bezierCurve.vertex(this.margin, this.height / 2 - this.arr[0]);
        for (int i = 1; i < this.maxLength; i++) {
          var posX = bezierCurve.float(i * this.pointGap + this.margin);
          var posY = bezierCurve.float(this.height / 2 - this.arr[i]);
          var c1 = bezierCurve.float((i - 1) * this.pointGap + this.margin);
          var c2 = bezierCurve.float(this.height / 2 - this.arr[i - 1]);
          var c3 = posX;
          var c4 = posY;
          bezierCurve.bezierVertex(c1, c2, c3, c4, posX, posY);
        }
        bezierCurve.endShape();
      }
    }
  }


  // Walk Line
  bezierCurve.stroke(23, 225, 0);
  bezierCurve.beginShape();
  bezierCurve.vertex(margin, height / 2 - walk[0]);
  for (int i = 1; i < walk.length; i++) {
    var posWX = bezierCurve.float(i * pointGap + margin);
    var posWY = bezierCurve.float(height / 2 - walk[i]);
    var cW1 = bezierCurve.float((i - 1) * pointGap + margin);
    var cW2 = bezierCurve.float(height / 2 - walk[i - 1]);
    var cW3 = posWX;
    var cW4 = posWY;
    bezierCurve.bezierVertex(cW1, cW2, cW3, cW4, posWX, posWY);
  }
}

var activitiesSketch = new p5(activitesCurve, 'activities');

“int i”? What is an “int”? It seems like some kind of identifier, but I’m a JavaScript parser, so that is pretty unexpected. :wink:

1 Like

Ah yes! you’re right, Jeremy, that did the trick.
I initially had this code in processing and then translated to P5js
So now that’s solved, I’ve run to another issue :unamused: : http://tiny.cc/c5wtbz
Pretty sure I’m not mistaken in defining the class here. What am I missing? Kindly advice? Thank you!

Just glancing at it, it looks like you have defined it as an inner class. So it isn’t in scope when you call new. Put the class definition at the top level of the sketch.

2 Likes

Thanks for the response, Jeremy!
The class was inside the draw function :shushing_face: