We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I use selectInput() in the following way (see the code), because i need to stop draw() when open file. It works, but is this correct ? There are some standard examples of selectInput() method ? Thanks.
cameyo
int io=0;
int counter=0;
PFont myFont;
void setup()
{
size(512, 512);
smooth();
background(0);
myFont = createFont("xkcd", 64);
textFont(myFont);
textAlign(CENTER);
io = 0;
counter=0;
}
void draw()
{
background(0);
text(counter, height/2, width/2);
counter++;
}
void keyPressed()
{
if (key == '1')
{
openData();
}
}
void openData()
{
println("open data...");
// stop the draw() function
noLoop();
selectInput("Select a file...", "myFile");
println("...function end.");
}
void myFile(File selection)
{
io=1;
if (selection == null)
{
println("No file selected.");
} else
{
println("File selected: " + selection.getAbsolutePath());
counter=0;
}
// restart the draw() function
loop();
io=0;
}
Answers
Might be a better idea to use a boolean and set it when the selection-window is opened or closed and in draw() you can draw/count etc. depending on that boolean. So you still have the option to do something in the background if you want that.
Yes. I use the "io" variable to do something on draw(). It is an integer (not boolean) because i can select use more choice (io=1 or io=0 or io=2 ecc.) Thanks.