We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi all, first post!
I'm using Buttons from the p5.dom library, but have run into a problem - how do I send arguments with my button presses?
At the moment I have
myButton.mouseClicked(doStuff);
so, pressing myButton calls the doStuff function.
How do I send an argument/parameter to doStuff function? I want to do something like:
myButton.mouseClicked(doStuff(foo))
Thanks in advance :)
** edit **
i'm trying real hard to not use global variables
** edit 2 **
i've put doStuff() inside setup(), so now have access to setup's variables - but is there a better way
Answers
thanks for your reply.
unfortunately I'm still a beginner JS coder and do not know about closures and consts.
it looks like i'm going to have to RTFM when i have time, and carry on with my inner function workaround as i have a deadline coming up.
Just accept that global variables are necessary for event callbacks.
That's the same case for Processing's Java Mode too! :P
const
-> https://developer.Mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/constUseful JS reference links:
thanks once again - they look like useful links
P.S.: You're using closures there w/o being aware of it! :>
Any outer variables used by your inner function belong to its closure! @-)