Hello, it’s me once again!
I’ve made some progress into my code, but now I’m thinking a little bit ahead and decided to share some questions with the community (ask for help, actually)
I’m prompting the user with a series of questions, then I want to have the answers saved into a neat little .txt file, so I can feed it into a treemap generator.
So far I managed to create and save some of the information, but things are not going smoothly.
I’m having trouble when saving all the answers into a single file. the ‘state’ variable seems to be working, all conditionals seems to be fulfilling its purposes but I still return with some null and/or weird file name/content. as a bonus I wish I could multiply the answers throughout my array, so they could appear a few more times (it will help with the visual effect of the treemaps). I thought about using a loop, randomizing 25 numbers for each of the 4 answers so far and making copies in to the array slot. Would it work?
Thanks a bunch, the code go as follow:
import controlP5.*;
ControlP5 cp5;
Textfield infosInput;
int state = 0;
int MAXSTATE = 3;
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("clique para continuar...")
;
infosInput = cp5.addTextfield("")
.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:
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:
cp5.get(Textarea.class, "titulo").setVisible(true);
cp5.get(Textarea.class, "clique").setVisible(true);
break;
case 2:
cp5.get(Textarea.class, "titulo").setVisible(false);
cp5.get(Textarea.class, "clique").setVisible(false);
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:
cp5.get(Textfield.class, "").setPosition(180, 80);
cp5.get(Textarea.class, "nome").setText("digite sua idade");
cp5.get(Textarea.class, "nome").setPosition(30, 280);
break;
}
}
void keyPressed() {
if ( key == RETURN || key == ENTER)
{
if (state == 3)
{
infosOutput[] = infos[];
saveStrings(infosOutput[0]+".txt", infosOutput);
println(infos);
}
if (state > 1)
{
infos = infos + "" + infosInput.getText();
println("boink");
}
state = (state+1) % (MAXSTATE+1);
println(state);
}
}