Callback function arguments

Hi, question about attaching event callback functions to an object in P5. Can those callback functions take arguments? for instance could I do something like this:

obj.mousePressed( function(argument));

?

Hi,

No, not that way you probably think about.
You should imagine, that the object calls your function on mousePressed event, and how the object should know, which argument it should use !?

But you can handle the cases inside the function ie.

obj.mousePressed(() => { 
  // calling foo with the required arg(s)
  foo(this.bar);
});

// ...

function foo(arg) { 
    // if (arg === whateverthis ) {
    //   do whatever this
    // else {
    //   do whatever that
    // }
} 

Cheers
— mnse

1 Like

thanks for the response!