5

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!

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 Commented Jul 3, 2018 at 3:05

2 Answers 2

6

Use

mousePressed(function() { toggleVideo(1);});
Sign up to request clarification or add additional context in comments.

Comments

0

With the latest JS, you can write the following:

function setup() {
 myButton.mousePressed(() => {
    toggleVideo(1)
 });
}

function toggleVideo(v) {
  blablabla[v].loop();
}  

1 Comment

This is basically the same as the previous answer.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.