'Problem creating a slider in p5.js "Uncaught reference : createSlider is not defined"
I am currently facing a problem in p5.js on openprocessing !
I try to add sliders to one of my sketches but the editor shows me an "Uncaught ReferenceError : createSlider is not defined"
Here is a part of my code
let slider;
let ellipses = [];
let colR = 10;
let colG = 10;
let colB = 10;
function setup() {
slider = createSlider(0, 255, 0, 1);
slider.position = (10, 10);
slider.style = ('width', '255px');
colR = random(255);
colG = random(255);
colB = random(255);
createCanvas(windowWidth, windowHeight);
background(100);
noStroke()
}
function draw() {
x = mouseX;
y = mouseY;
let val = slider.value();
background(val);
if (mouseIsPressed) {
if (mouseButton == LEFT) {
ellipses.push(new Ellipse());
}
}
for (let i = 0; i < ellipses.length; i++) {
ellipses[i].display();
ellipses[i].move();
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/1.4.0/p5.min.js"></script>
the class Ellipse is a class I made that works just fine, and I don't think it is related to my problem.
Wondering why it wouldn't recognize the createSlider function, I tried creating a new sketch from scratch and simply make it a slider doing the same thing and just made this :
let slider;
function setup() {
createCanvas(windowWidth, windowHeight);
background(100);
slider = createSlider(0,255,0,25);
slider.position(10,10);
slider.style('width','250px');
}
function draw() {
let val = slider.value();
background(val);
}
What surprised me here is that this works perfectly fine without anything else, on the same editor and website. So I went back to my original code but I just can't see what to do here to make it work as the code itself is absolutely the same. I also tried moving lines relating to the slider here and there but it doesn't change anything, I'm stuck.. Thx if anyone finds a solution to my problem :)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
