Hello everyone, I find little to no time to actually tidy up my coding macarroni, sorry if it sounds or seems to confusing.
I tried to comment as much as I could into my original code, which I’m going to post, but I think I should address my question a little more directly: what is the best method for reading from cp5 textfields and writing into a single .txt file? at first I thought about using a buffer string array in order to save each question in a single array slot (I’m rusty into coding slang, are there array ‘slots’? hahahah) and then, using some kind of ‘randomizer’ tool, I’d also multiply the user answers throughout the string, in order to achieve a visual result similar to this: http://www.generative-gestaltung.de/2/sketches/?01_P/P_3_1_4_01.
/*
enTro
*/
import controlP5.*;
ControlP5 cp5;
Textfield infosInput; // naming textfield for better calling throughout the code
int state = 0;
int MAXSTATE = 3; // numbers of questions to implement switch/case
String infos;
String infosOutput[];
void setup(){
size (500, 500);
cp5 = new ControlP5(this);
cp5.addTextarea("titulo")
.setPosition(100, 100)
.setSize(400, 40)
.setFont(createFont("arial", 30))
.setLineHeight(14)
.setColor(color(128))
.setColorBackground(color(185, 100))
.setColorForeground(color(255, 100))
.setText("enTro");
cp5.addTextarea("clique")
.setPosition(280, 295)
.setSize(200, 25)
.setFont(createFont("arial", 12))
.setLineHeight(14)
.setColor(color(135))
.setColorBackground(color(198, 100))
.setColorForeground(color(255, 100))
.setText("ENTER para continuar...")
;
infosInput = cp5.addTextfield("") //declared earlier, I name the textfield to aid later calling
.setPosition(120, 100)
.setSize(390, 30)
.setFont(createFont("arial", 30))
.setColor(color(128))
.setColorBackground(color(185, 100))
.setColorForeground(color(255, 100))
;
cp5.addTextarea("nome")
.setPosition(20, 350)
.setSize(320, 40)
.setFont(createFont("arial", 30))
.setLineHeight(14)
.setColor(color(120))
.setColorBackground(color(195, 100))
.setColorForeground(color(249, 100))
.setText("digite seu nome");
}
void draw(){
background(0);
switch (state) {
case 0: //splash screen
cp5.get(Textarea.class, "titulo").setVisible(true);
cp5.get(Textarea.class, "clique").setVisible(false);
cp5.get(Textarea.class, "nome").setVisible(false);
cp5.get(Textfield.class, "").setVisible(false);
break;
case 1: //enter to continue
cp5.get(Textarea.class, "titulo").setVisible(true);
cp5.get(Textarea.class, "clique").setVisible(true);
break;
case 2: //user inputs their name
cp5.get(Textarea.class, "titulo").setVisible(false);
cp5.get(Textarea.class, "clique").setVisible(false); //hides unused textfields
cp5.get(Textfield.class, "").setVisible(true);
cp5.get(Textfield.class, "").setPosition(120, 100);
cp5.get(Textarea.class, "nome").setVisible(true);
cp5.get(Textarea.class, "nome").setText("digite seu nome");
cp5.get(Textarea.class, "nome").setPosition(20, 350);
break;
case 3: //user inputs their age
cp5.get(Textfield.class, "").setPosition(180, 80);
cp5.get(Textarea.class, "nome").setText("digite sua idade"); //changes the question of the box, in order to avoid creating multiple fields
cp5.get(Textarea.class, "nome").setPosition(30, 280); //slightly changes the position for aesthetics
break;
}
}
void keyPressed() {
if ( key == ENTER || key == RETURN)
{
if (state == 3)
{
/*infosOutput[] = infos[];
saveStrings(infosOutput[0]+".txt", infosOutput);
println(infos);
this step is reserved for saving the string into a .txt, but it raises the question: is it better to do
after each single keypress or at the very end of the program, when a whole string is formed?
that written, need to research a method for:
- saving textfield into a .txt;
- each answer from the user is stored in the same .txt;
- preferrably in this step I already multiply randomly the answers throughout the strings, in order to generate a treemap afterwards:
http://www.generative-gestaltung.de/2/sketches/?01_P/P_3_1_4_01;
*/
}
if (state > 1)
{
infos = infos + "" + infosInput.getText(); //is this valid? lol
println("boink"); //checking if the programs enters this conditional
}
state = (state+1) % (MAXSTATE+1);
println(state);
}
}