javascript - p5js button.mousePressed calls function + arguments? - Stack Overflow

probably silly question but is this possible or not in p5js?function setup() {myButton.mousePressed(tog

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
Add a ment  | 

2 Answers 2

Reset to default 6

Use

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();
}  

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744385490a4571642.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信