We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I'm using the code from this example to open a file.
https://www.processing.org/reference/selectInput_.html
The issue I am having is that the code in my Setup and Draw function is starting to execute before I select a file.
I need my sketch to wait until I choose a file then proceed.
Any ideas?
Thanks.
Phil
void setup() {
selectInput("Select a file to process:", "fileSelected");
size(img.width, img.height);
}
void draw() {
}
void fileSelected(File file) {
if (file == null) {
println("Window was closed or the user hit cancel.");
} else {
println("User selected " + file.getAbsolutePath());
img = loadImage(file.getPath()); // Load the image into the program
}
}
Answers
I tried your code and I get a NULL pointer exception on this line :
image(myMovie, 0, 0, 600, 400);
Below is my code..
Any ideas?
Thanks.
Phil
I believe you still hadn't realized that selectInput() doesn't block. Program goes on w/o waiting for it to finish!
You gotta keep checking whether it was successful all the time, unfortunately. /:)
void setup() { selectInput("Select a file to process:", "fileSelected");
size(img.width, img.height);
}
void draw() {
}
void fileSelected(File file) { if (file == null) { println("Window was closed or the user hit cancel."); } else { println("User selected " + file.getAbsolutePath()); img = loadImage(file.getPath()); // Load the image into the program
} }
Can i get an alternate to select input, i have to specify the path in the location itself anf call back it.
please don't bump threads from 2014.
if the above answers don't already solve your problem then start a new thread. and format your code nicely by selecting it and pressing ctrl-o