I am trying to use the p5js.gui library to collect a simple text input and then just output that input to the screen. I have tried a number of different approaches but keep running into errors. This is what I have so far.
let button;
function setup() {
var inp = createInput('');
inp.position(100,100);
newInput = inp.input(myInputEvent);
button = createButton('click me');
button.position(19, 19);
button.mousePressed(changeText(newInput));
createCanvas(500, 500);
}
function myInputEvent() {
//console.log('you are typing: ', this.value());
var myInput = this.value();
return myInput;
}
function changeText(nextInput){
text (nextInput, 100, 200);
}
I have had some success by moving the text output to the myInputEvent() function but it prints it out as I am entering into the text field. I want to print out only when the button is clicked.
I believe the issue might be that I am not properly passing the value from one function to another, but am not really sure.
Any help is appreciated.