We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hey! What I want to do using the ControlP5 library: create an input textfield, where I can write limited amount of characters, e.g. minimum 1 and maximum 10 and after pressing Enter to save the String in another variable. ONLY ONE input should be possible (so I have to block the field somehow after receiving the input)! Problems: - I don't know how to limit the chracters amount and the number of inputs to only one - After running the sketch the text field is active and I can write there as usual, but once I click outside I can't activate the field again. I think it's because in my code there is a mouseClicked() function, but I don't know how to fix this...
P.S. Is the variable secretMessage right in the public void input(String theText) or should/could it be somewhere else? Thank you!
My code (not complete):
`import controlP5.*;
ControlP5 cp5;
String textValue = ""; String secretMessage;
void setup() { size(700,400);
PFont font = createFont("arial",20);
cp5 = new ControlP5(this);
cp5.addTextfield("input") .setPosition(20,100) .setSize(200,40) .setFont(font) .setFocus(true) .setColor(color(255,0,0)) .setMax(3); ;
textFont(font); }
void draw() { background(0); fill(255); text(textValue, 360,180); }
public void clear() { cp5.get(Textfield.class,"textValue").clear(); }
public void input(String theText) { secretMessage=theText; println("Your secret message: "+secretMessage+" has length "+secretMessage.length()); }
...
void mouseClicked() { for(int i=0;i<n;i++) { if(mouseX>x[i] && mouseX<(x[i]+105) && mouseY>y[i] && mouseY<(y[i]+130)&& clicked[i]==false) { doSomething(); } } }`