Cannot refer to the non-final local variable ... defined in an enclosing scope

Hi, I am trying a code found on the internet (below). When I run it, I obtain this message:
“cannot refer to the non-final local variable startw defined in an enclosing scope”
What is it supposed to mean ? What can I do to solve this ?
Thanks in advance!
Renaud

float startw;  
startw = 15 + random(50);

class Branch {

  float xp1;
  float xp2;
  float yp1;
  float yp2;

  void render() {

    float hyp = sqrt(pow((xp2 - xp1), 2) + pow((yp2 - yp1), 2));
    for (float i=0; i < hyp; i+=3) {
      rectMode(CENTER);
      noStroke();
    };
    startw = (startw -   (hyp * ((startw - pow(startw, 0.9))/hyp)));

    popMatrix();
  };
};
1 Like

not every code is worth copying

pls. start over with your own code
after a description of steps what you want to do…

I think the code above is an example of something not worth copying. Even if you solve this problem your program will crash because there is no matching pushMatrix() for the popMatrix()

First, above comments are correct – that code is trash. Start by defining your problem, ask for help on that.

If your sketch uses classes and functions (like draw() and setup()) then don’t put lines of code outside a function.

Don’t do this:

float foo;
foo = 15 + random(50); // DON'T compute outside a function / method / class!
void draw(){
  println(foo);
}

but instead do this:

float foo;
void setup(){
  foo = 15 + random(50); // DO compute inside a function / method / class!
}
void draw(){
  println(foo);
}

All right ! Thanks for your help !