0

Does the fileselected function in this code complete its execution even before while loop execution?

void setup()
{ 
size(800, 600);
selectInput("Select a file to process:", "fileSelected"); 
while(data==null)
{
 delay(1000);
}
 }
 void fileselected()
  {
   *
    *

   *

  *

  }

How do I make the draw function wait until it receives the necessary arguments to run?

Stephen Kennedy
  • 20,585
  • 22
  • 95
  • 108
shiva allani
  • 41
  • 1
  • 2
  • 6
  • 1
    Please [debug your program](http://happycoding.io/tutorials/processing/debugging) and narrow your problem down to a [mcve]. – Kevin Workman Feb 18 '18 at 22:04
  • Im not able to figure out where exactly the issue is. problem could be in the draw() function of proj4.pde. – shiva allani Feb 18 '18 at 22:11
  • That isn't really how Stack Overflow works. Please debug your code. What is the value of every variable on that line? One of them is `null`. Figure out why that is, and post a [mcve] if you're still stuck. Good luck. – Kevin Workman Feb 18 '18 at 22:19
  • This is now a completely different question than you originally posted? – Kevin Workman Feb 18 '18 at 23:22
  • Why are you asking us question 1? You should just be able to **test it yourself**. – Makyen Feb 20 '18 at 23:33

1 Answers1

2

does setup and draw function run parallel in processing

No. First the setup() function is called and completes, then the draw() function is called 60 times per second.

does the fileselected function completes its execution even before while loop execution.

The fileSelected() function will be called when the user selects a file. You really shouldn't call the delay() function in a loop like that.

How do I make the draw function to wait until it receives the necessary arguments to run.

Something like this:

boolean fileLoaded = false;

void setup(){ 
  size(800, 600);
  selectInput("Select a file to process:", "fileSelected"); 
}

void fileSelected(File selection){
  fileLoaded = true;
}

void draw(){
  if(!fileLoaded){
    //short-circuit and stop the function
    return;
  }
}

You could go a step further and use the noLoop() and loop() functions. More info can be found in the reference.

Kevin Workman
  • 41,537
  • 9
  • 68
  • 107