unexpected token?

edited July 2015 in Questions about Code

I'm trying to figure out where I went wrong. Since I made a few changes from a code I duplicate. I encounter this error. I'm again a newbie. Any response to the problem soon will be appreciated. Thanks.

ArrayList<PVector>allVectors;

float wanderSpeed = 2.3;
int numSteps = 12;

float lineHue = 2.1;
float lineSat = 0.0;
float lineBright = 1.2;
float lineShaows = 0.68;

boolean autoplay = true;

 void setup()
 {
   size(850,300);
   colorMode(HSB, 50, 60, 40);
   backgrounf(0);
   nofill();

   createline();
   reandomizeColor();
}

 void draw()
{
  strokeweigth(2.01);
  //randomize color
  if (random (0,1)>colorTrigger)randomizeColor();

  stroke(lineHue, lineSat,lineBright, 0.0);
  fill(255);

  //draw line
  {
    beginShape();
    for(int i = 0; i <allVectors.size(); i++)
    {
    PVector vector = allvectors.get(i);
    if (i == 0) curveVertex(vector.x, vector.y);
    curveVertex(vertex.x, vertex.y);
    if (i == allvectors.size() - 1) curveVertex(verctor.x, vector.y);
    }
    endShape();

    checkAutoplay();
  }

 void checkAutoplay()
 {
  if (autoplay)
   {
    // reset if line has left screen
    for (int i = 0; i<allVectors.size (); i++)
     {
      PVector vector = allVectors.get(i);
      if (vector.y < height) return;

     }
    // reset if boundary check didn't exit functiion
    reset();
    }
  }


 void createLine()
{
  allVectors = new ArrayList<PVector>();

  for (int i=0; i<=numSteps; i++)
  {
    PVector vector = new PVector(i * width/numSteps, height/2);
    allVectors.add(vector);
  }
}

 void randomizeColor()
{
  lineHue = random(0, 1);
  lineSat = random(0, 1);
}

 void reset()
{
  background(0.0);
  createLine();
  randomizeColor();
  wanderSpeed = random(0.3, 2.0);
  numSteps = (int)random(1, 20);
  colorTrigger = random(0.99, 0.9999);
}

Answers

  • http://forum.processing.org/two/discussion/8045/how-to-format-code-and-text

    Hit CTRL+T inside Processing's IDE (PDE). It will indent the text and help ya spot the error!

  • edited July 2015 Answer ✓

    You're declaring checkAutoplay() inside of the draw() function, which isn't allowed. It looks to me like you're missing a right } at line 47.

    Edit: The code is also full of typos which give appropriate error messages. Note that capitalization matters in function names.

  • Hey, GoToLoop, thanks for the reply

    And yeah, I did align the code. The error remains the same in the IDE.

    check Autoplay()

    where the error message display

    "unexpected token : void"

    Please help. :(

    ArrayList<PVector>allVectors;
    
    float wanderSpeed = 2.3;
    int numSteps = 12;
    
    float lineHue = 2.1;
    float lineSat = 0.0;
    float lineBright = 1.2;
    float lineShaows = 0.68;
    
    boolean autoplay = true;
    
    void setup()
    {
      size(850, 300);
      colorMode(HSB, 50, 60, 40);
      backgrounf(0);
      nofill();
    
      createline();
      reandomizeColor();
    }
    
    void draw()
    {
      strokeweigth(2.01);
      //randomize color
      if (random (0, 1)>colorTrigger)randomizeColor();
    
      stroke(lineHue, lineSat, lineBright, 0.0);
      fill(255);
    
      //draw line
      {
        beginShape();
        for (int i = 0; i <allVectors.size (); i++)
        {
          PVector vector = allvectors.get(i);
          if (i == 0) curveVertex(vector.x, vector.y);
          curveVertex(vertex.x, vertex.y)%3
    
  • You have a random stray opening bracket on line 34. Those usually only need to appear after functions definitions, for loops, if conditions, and else statements.

    Also, you've not posted a complete sketch at all yet. Both of your attempts have just sort of ended without any "closure".

  • edited July 2015

    Thanks guys, but after working upon the typos I'm yet missing upon something. The output sketch is blank.

        ArrayList<PVector>allVectors;
    
        float wanderSpeed = 3.3;
        int numSteps = 12;
    
        float lineHue = 2.1;
        float lineSat = 0.0;
        float lineBright = 1.5;
        float colorTrigger = 0.976;
    
        boolean autoplay = true;
    
        void setup()
        {
          size(940, 540);
          colorMode(HSB, 1.0,1.0 ,1.0 );
          background(0.0);
          noFill();
    
          createLine();
          randomizeColor();
        }
    
        void draw()
        {
          strokeWeight(1.01);
          //randomize color
          if (random (0, 1)>colorTrigger)randomizeColor();
    
          stroke(lineHue, lineSat, lineBright, 0.0);
          fill(255);
    
          //draw line
    
            beginShape();
            for (int i = 0; i <allVectors.size (); i++)
            {
              PVector vector = allVectors.get(i);
              if (i == 0) curveVertex(vector.x, vector.y);
              curveVertex(vector.x, vector.y);
              if (i == allVectors.size() - 1) curveVertex(vector.x, vector.y);
            }
            endShape();
    
            checkAutoplay();
          }
    
    
        void checkAutoplay()
        {
          if (autoplay)
          {
            // reset if line has left screen
            for (int i = 0; i<allVectors.size (); i++)
            {
              PVector vector = allVectors.get(i);
              if (vector.y < height) return;
            }
            // reset if boundary check didn't exit functiion
            reset();
          }
        }
    
    
        void createLine()
        {
          allVectors = new ArrayList<PVector>();
    
          for (int i=0; i<=numSteps; i++)
          {
            PVector vector = new PVector(i * width/numSteps, height/2);
            allVectors.add(vector);
          }
        }
    
        void randomizeColor()
        {
          lineHue = random(0, 1);
          lineSat = random(0, 1);
        }
    
        void reset()
        {
          background(0.0);
          createLine();
          randomizeColor();
          wanderSpeed = random(0.3, 2.0);
          numSteps = (int)random(1, 20);
          colorTrigger = random(0.99, 0.9999);
        }
    
  • Answer ✓

    On line 30, you set the alpha value for your line's color to 0. This makes your line completely transparent, so it does not appear. Remove the fourth value in your call to stroke().

  • edited August 2015

    my make output ' Hey, finally got something out of it. Though I wish to make the lines much more smoother and texture little lighter. I killed the stroke value and added wanderSpeed function to the as increment and decrement value to vectors x and y. Hence would like to look into it further, and more dynamic functions.Nevertheless felt like sharing :)#1

Sign In or Register to comment.