# Error (: line 0)

**URL:** <https://discourse.processing.org/t/error-line-0/26427>\
**Category:** Coding Questions\
**Created:** [December 21, 2020, 8:04pm UTC](https://discourse.processing.org/t/error-line-0/26427 "2020-12-21T20:04:04Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![iris.go](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@iris.go](https://discourse.processing.org/u/iris.go)\
**Post date:** [December 21, 2020, 8:04pm UTC](https://discourse.processing.org/t/error-line-0/26427/1 "2020-12-21T20:04:04Z")

</div>

Good day,

I am new to this forum and would like to have your advice concerning an error which I am not able to solve. When I run the code below (tree simulation) in p5js,  
it gives me this error : Script error. (: line 0).

I would like tho know if you have any idea how to solve this.

Best wishes.

Iris

\<  
var dotSize = 9;  
var angleOffsetA;  
var angleOffsetB;

function setup() {  
createCanvas(windowWidth, windowHeight);  
noStroke();  
fill(0);  
frameRate(1); // Redraw the tree once second

angleOffsetA = radians(1.5);//Convert 1.5 degrees to radians  
angleOffsetB = radians(50); //Convert 50 degrees to radians  
}

function draw() {  
background(255);  
seed1(dotSize, radians(270), width/2, height); //Start the tree  
}

function seed1(dotSize, angle, x, y) {

if (dotSize \> 1.0){

//Create a random numbers between 0 and 1  
var r = random(0, 1.0);

//98% chance this will happen  
if (r \> 0.02) {  
ellipse(x, y dotSize, dotSize);  
var newx = x + cos(angle) \* dotSize;  
var newy = y + sin(angle) \* dotSize;  
seed1(dotSize \* 0.99,angle - angleOffsetA, newx, newy);  
}  
//02% chance this will happen  
else{  
var newx = x + cos(angle);  
var newy = y + sin(angle);  
seed2(dotSize \* 0.99,angle + angleOffsetA, newx, newy);  
seed1(dotSize \* 0.60,angle + angleOffsetB, newx, newy);  
seed2(dotSize \* 0.50,angle - angleOffsetB, newx, newy);

}  
}  
}

function seed2(dotSize, angle, x, y) {

if (dotSize \> 1.0) {

//Create a random numbers between 0 and 1  
var r = random(0, 1.0);

//95% chance this will happen  
if (r \> 0.05) {  
ellipse(x, y, dotSize, dotSize);  
var newx = x + cos(angle) \* dotSize;  
var newy = y + sin(angle) \* dotSize;  
seed2(dotSize \* 0.99,angle - angleOffsetA, newx, newy);  
}

//05% chance this will happen  
else {  
ellipse(x, y, dotSize, dotSize);  
var newx = x + cos(angle);  
var newy = y + sin(angle);  
seed2(dotSize \* 0.99,angle + angleOffsetA, newx, newy);  
seed1(dotSize \* 0.60,angle + angleOffsetB, newx, newy);  
seed2(dotSize \* 0.50,angle - angleOffsetB, newx, newy);  
}  
}  
}  
function mousePressed (){  
background(255,45);  
seed1(dotSize, radians(270, mouseX, height);  
}  
/\>  
Homework policy: [https://discourse.processing.org/t/faq-guidelines/5#homework](https://discourse.processing.org/t/faq-guidelines/5#homework)  
Asking Questions: [Guidelines—Asking Questions](https://discourse.processing.org/t/guidelines-asking-questions/2147)  
–\>

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 21, 2020, 9:12pm UTC](https://discourse.processing.org/t/error-line-0/26427/2 "2020-12-21T21:12:51Z")

</div>

I found some issues. It is mostly misplaced “}” and a forgotten “)”.

here is the fixed code:

```auto
var dotSize = 9;
var angleOffsetA;
var angleOffsetB;

function setup() {
  createCanvas(windowWidth, windowHeight);
  noStroke();
  fill(0);
  frameRate(1); // Redraw the tree once second

  angleOffsetA = radians(1.5); //Convert 1.5 degrees to radians
  angleOffsetB = radians(50); //Convert 50 degrees to radians
}

function draw() {
  background(255);
  seed1(dotSize, radians(270), width / 2, height); //Start the tree
}

function seed1(dotSize, angle, x, y) {

  if (dotSize > 1.0) {

    //Create a random numbers between 0 and 1
    var r = random(0, 1.0);

    //98% chance this will happen
    if (r > 0.02) {
      circle(x, y, dotSize);
      var newx = x + cos(angle) * dotSize;
      var newy = y + sin(angle) * dotSize;
      seed1(dotSize * 0.99, angle - angleOffsetA, newx, newy);
    }
  }
  //02% chance this will happen
  else {
    var newx = x + cos(angle);
    var newy = y + sin(angle);
    seed2(dotSize * 0.99, angle + angleOffsetA, newx, newy);
    seed1(dotSize * 0.60, angle + angleOffsetB, newx, newy);
    seed2(dotSize * 0.50, angle - angleOffsetB, newx, newy);

  }
}

function seed2(dotSize, angle, x, y) {

  if (dotSize > 1.0) {

    //Create a random numbers between 0 and 1
    var r = random(0, 1.0);

    //95% chance this will happen
    if (r > 0.05) {
      ellipse(x, y, dotSize, dotSize);
      var newx = x + cos(angle) * dotSize;
      var newy = y + sin(angle) * dotSize;
      seed2(dotSize * 0.99, angle - angleOffsetA, newx, newy);
    }

    //05% chance this will happen
    else {
      ellipse(x, y, dotSize, dotSize);
      var newx = x + cos(angle);
      var newy = y + sin(angle);
      seed2(dotSize * 0.99, angle + angleOffsetA, newx, newy);
      seed1(dotSize * 0.60, angle + angleOffsetB, newx, newy);
      seed2(dotSize * 0.50, angle - angleOffsetB, newx, newy);
    }
  }
}

function mousePressed() {
  background(255, 45);
  seed1(dotSize, radians(270, mouseX, height));
}

```

---

<div class="post-metadata">

**Author:** ![iris.go](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@iris.go](https://discourse.processing.org/u/iris.go)\
**Post date:** [December 21, 2020, 9:48pm UTC](https://discourse.processing.org/t/error-line-0/26427/3 "2020-12-21T21:48:13Z")

</div>

Thank you so much codeMasterX!

I should be more careful with these “{“ and these “)”, it solves a part of the problem. However, I still have the error message followed by this message:

Script error. (: line 0)

If not intentional, this is often a problem with scope: [[https://p5js.org/examples/data-variable-scope.html](https://p5js.org/examples/data-variable-scope.html)]. ([http://p5js.org/reference/#/p5/circle](http://p5js.org/reference/#/p5/circle))

I will try to get more insight from the link they provided.

Thanks again for your help!

Iris

---

<div class="post-metadata">

**Author:** ![CodeMasterX](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/codemasterx/32/2942_2.png) [@CodeMasterX](https://discourse.processing.org/u/CodeMasterX)\
**Post date:** [December 21, 2020, 10:03pm UTC](https://discourse.processing.org/t/error-line-0/26427/4 "2020-12-21T22:03:48Z")

</div>

I don’t really understand what this program is supposed to do : P so I can’t fix it. I am not too good at reading code and determining what is supposed to happen.

---

<div class="post-metadata">

**Author:** ![iris.go](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@iris.go](https://discourse.processing.org/u/iris.go)\
**Post date:** [December 21, 2020, 10:20pm UTC](https://discourse.processing.org/t/error-line-0/26427/5 "2020-12-21T22:20:36Z")

</div>

The code is supposed to draw a different tree shape every time we press the mouse. 🙂

---

<div class="post-metadata">

**Author:** ![iris.go](https://avatars.discourse-cdn.com/v4/letter/i/c57346/32.png) [@iris.go](https://discourse.processing.org/u/iris.go)\
**Post date:** [December 21, 2020, 10:56pm UTC](https://discourse.processing.org/t/error-line-0/26427/6 "2020-12-21T22:56:07Z")

</div>

![Screenshot 2020-12-21 at 5.55.22 PM](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/d/dffa8f59505cad9b4c1a0a2d9805fabce494ce3f.jpeg)
