probably silly question but is this possible or not in p5js?
function setup() {
myButton.mousePressed(toggleVideo(1)); //This toggleVideo works well without argument
}
function toggleVideo(v) {
blablabla[v].loop();
}
Many thanks!
probably silly question but is this possible or not in p5js?
function setup() {
myButton.mousePressed(toggleVideo(1)); //This toggleVideo works well without argument
}
function toggleVideo(v) {
blablabla[v].loop();
}
Many thanks!
Share Improve this question edited Feb 20, 2018 at 21:35 H.Scheidl 8554 gold badges11 silver badges25 bronze badges asked Feb 28, 2016 at 9:24 AfzhalAfzhal 511 silver badge2 bronze badges 1- The reason yours doesn’t work is because mousePressed takes in the variable that references the function, namely, toggleVideo. By putting the parentheses you are actually calling the function which executes when reached in setup – Moshe Goldberg Commented Jul 3, 2018 at 3:05
2 Answers
Reset to default 6Use
mousePressed(function() { toggleVideo(1);});
With the latest JS, you can write the following:
function setup() {
myButton.mousePressed(() => {
toggleVideo(1)
});
}
function toggleVideo(v) {
blablabla[v].loop();
}