# Script error. (:line 0)

**URL:** <https://discourse.processing.org/t/script-error-line-0/4871>\
**Category:** Coding Questions\
**Created:** [October 25, 2018, 4:16pm UTC](https://discourse.processing.org/t/script-error-line-0/4871 "2018-10-25T16:16:40Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 25, 2018, 4:16pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/1 "2018-10-25T16:16:40Z")

</div>

Hi,  
I’m just beginning with this library and I have trouble to start.  
When I play my code, I have a "Script error. (:line 0) " message in the console.  
I identified where the problem happpens in my code but I have no idea why.  
It seems to be related to the z coordinate of my point (line 48 see code below).  
Can anyone help ?  
Thx in advance.  
Sebastien

```auto
var ps = null;

function setup(){
  createCanvas(1000, 400, WEBGL);
	ps = new ParticleSystem (10, 10, 5, 5, createVector(width/2, height/2, 0));
}

function draw(){
  background(0);
  ps.run();
}

var ParticleSystem = function(numX,numZ,stepX,stepZ,v) {
  	this.particles = [];
		this.origin = v.copy();
		this.varDepth = stepZ;
    for(var i = 0; i < numZ; ++i){
			for(var j = 0; j < numX; ++j){
        //Vector in absolute
				var particlePos = createVector((numX*stepX/2)-j*stepX,0,(numZ*stepZ/2)-i*this.varDepth)
        //Vector relative to Canvas
        this.particles.push(new Particle(this.origin.sub(particlePos)));
        
    }}
}

ParticleSystem.prototype.run = function() {

    var len = this.particles.length;

    //loop through and run particles
    for (var i = len - 1; i >= 0; i--) {
        var particle = this.particles[i];
        particle.run()
    }
}

var Particle = function (pos) {
    this.loc = pos;
}

Particle.prototype.run = function() {
  	this.display()
}

Particle.prototype.display = function() {
  	stroke(255);
    point(this.loc.x, this.loc.y, this.loc.z);
  
}

```

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [October 25, 2018, 7:33pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/3 "2018-10-25T19:33:40Z")

</div>

I’m not getting an error when I run this (but the screen is completely black). Maybe it is something to do with your index.html–can we see it?

---

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 25, 2018, 8:15pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/4 "2018-10-25T20:15:10Z")

</div>

Hello WizardBear,  
Nothing fancy about the HTML, just the canvas.  
The code above is a first attempt to display a white 3d dot Matrix particles system.  
If you have an idea about why nothing happens, I’m interested.  
Thx

```auto
<!DOCTYPE html>

<html>

  <head>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/p5.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/addons/p5.dom.min.js"></script>

    <script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.7.2/addons/p5.sound.min.js"></script>

    <link rel="stylesheet" type="text/css" href="style.css">

    <meta charset="utf-8" />
​

  </head>

  <body>

    <script src="sketch.js"></script>

  </body>

</html>

```

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [October 25, 2018, 8:20pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/5 "2018-10-25T20:20:19Z")

</div>

I think stuff is happening–you just can’t see it as it isn’t on the canvas. (Working in 3D is hard. 😅)  
I am just a bit confused as to why you are getting an error. Is the code running?

---

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 26, 2018, 6:48am UTC](https://discourse.processing.org/t/script-error-line-0/4871/6 "2018-10-26T06:48:21Z")

</div>

Nope, it’s not running. The problem happens when I draw the point

```auto
Particle.prototype.display = function() {
  stroke(255);
  	
    point(this.loc.x, this.loc.y, this.loc.z);
  
}

```

… and more specificallly in the z component of the point. When I remove the z, it works.

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [October 26, 2018, 9:02am UTC](https://discourse.processing.org/t/script-error-line-0/4871/7 "2018-10-26T09:02:10Z")

</div>

You are running it in the p5.js web editor, right?  
Do you get this message in the console:  
`p5.RendererGL: enabled webgl context`

---

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 26, 2018, 12:14pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/8 "2018-10-26T12:14:00Z")

</div>

Yes  
I also tried to replace the point with a sphere and it works. So it’s a problem with the use of the point with WEBGL.  
This piece of code works almost as expected except I wanted to use real dots at first and also that I don’t understand why the animation is pausing for 2 secs every 1 sec (but that’s probably a completely different issue problem)

```auto
var ps = null;

function setup(){
  createCanvas(1000, 400, WEBGL);
	ps = new ParticleSystem (20, 20, 20, 20, createVector(0,50,0));
}

function draw(){
  background(0);
  ps.run();
}

var ParticleSystem = function(numX,numZ,stepX,stepZ,v) {
  	this.particles = [];
		this.varDepth = stepZ;
    for(var i = 0; i < numZ; ++i){
			for(var j = 0; j < numX; ++j){
        //Vector in absolute
				var canvasOrigin = v.copy()
        var matrixOrigin = createVector((numX*stepX/2)-j*stepX,0,(numZ*stepZ/2)-i*this.varDepth)
        //Vector relative to Canvas
        
        this.particles.push(new Particle(canvasOrigin.sub(matrixOrigin)));
        
    	}
    }
}

ParticleSystem.prototype.run = function() {

    var len = this.particles.length;

    //loop through and run particles
    for (var i = len - 1; i >= 0; i--) {
        var particle = this.particles[i];
        particle.run()
    }
}

var Particle = function (pos) {
    this.loc = pos.copy();
  	this.radius = 0.1;
}

Particle.prototype.run = function() {
  this.update();	
  this.display()
}

Particle.prototype.update = function() {
		this.radius = randomGaussian(0.2, 0.1);
}

Particle.prototype.display = function() {
  	stroke(255);
  	push();
    translate(this.loc.x, this.loc.y, this.loc.z);	
    sphere(this.radius,4,4);
  	pop();
  
}

```

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [October 26, 2018, 12:15pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/9 "2018-10-26T12:15:48Z")

</div>

So problem solved? 😁

---

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 26, 2018, 1:24pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/10 "2018-10-26T13:24:23Z")

</div>

Hmmm not really … I would have preferred to use dots instead of spheres … and it’s frustrating not to understand why it doesn’t do what I want.  
I will leave it opened just a little time more in case someone would have a flash.  
Thank you though !

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [October 26, 2018, 1:40pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/11 "2018-10-26T13:40:11Z")

</div>

I think it is because `point()` works with pixels, which you can only really do in a 2D environment as the screen of pixels is 2D and you are essentially coloring one of those pixels. `sphere()` is much more versatile as it is built to be used in a 3D environment.

> I will leave it opened just a little time more in case someone would have a flash.

You’re not going to delete this topic are you?

---

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 26, 2018, 1:46pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/12 "2018-10-26T13:46:52Z")

</div>

But the point() object is accessible in WEBGL : [https://p5js.org/reference/#/p5/point](https://p5js.org/reference/#/p5/point)  
I also have to try it on another development environment to confirm the issue.

No I will not delete the topic but I thought there was a “solved” button to click but I realise that not.  
So the topic will stay as it is.

---

<div class="post-metadata">

**Author:** ![TheWizardBear](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thewizardbear/32/3552_2.png) [@TheWizardBear](https://discourse.processing.org/u/TheWizardBear)\
**Post date:** [October 26, 2018, 2:00pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/13 "2018-10-26T14:00:47Z")

</div>

Oh yeah, maybe you have to set a strokeWeight?

Yeah we really could do with a solved button.

---

<div class="post-metadata">

**Author:** ![SebC](https://avatars.discourse-cdn.com/v4/letter/s/dbc845/32.png) [@SebC](https://discourse.processing.org/u/SebC)\
**Post date:** [October 26, 2018, 3:11pm UTC](https://discourse.processing.org/t/script-error-line-0/4871/14 "2018-10-26T15:11:35Z")

</div>

OK … pb is the online editor. It works perfectly in local.  
Definitely solved now !
