We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › About the noLoop() and loop(), what do they do
Page Index Toggle Pages: 1
About the noLoop() and loop(), what do they do? (Read 1352 times)
About the noLoop() and loop(), what do they do?
Jan 9th, 2010, 8:09pm
 
I don't quite know what happens after I call noLoop(). I used to struggle to not freeze my program when I use a swing dialog to input data. I found I would not freeze my program if I sandwich the dialog between noLoop() and loop().
I also ran into trouble when I call noLoop() before I push esc to stop the program. I have an audio lib minim stop stuff in the stop(). If I don't call noLoop() and stop the program, nothing goes bad. If I call noLoop() before I stop the program, then the player.close() gives nullPointerException error.

What exactly does these two functions do? Thanks.
Re: About the noLoop() and loop(), what do they do?
Reply #1 - Jan 9th, 2010, 8:28pm
 
Here's the ref doc: http://processing.org/reference/noLoop_.html

From what I understand, it stops/starts the draw() looping.  By default, the draw() will loop.
Re: About the noLoop() and loop(), what do they do?
Reply #2 - Jan 10th, 2010, 11:21am
 
i use the noloop() if i have a function that i dont want to loop but only run once and then return

function {
for(...){
blabla}
noloop()
}

because sometimes the function i use loop by itself without me doing anything.

but else use it for a draw function that you dont want to loop.
mostly i use this when i have keyPressed or other functions that can take care of program running instead of draw.
sorry my english Smiley
Re: About the noLoop() and loop(), what do they do?
Reply #3 - Jan 10th, 2010, 11:27am
 
i dont know if this isnt missleading. As far as i know the whole sketch stops no matter where you put it. so always be aware that it not only stops the funtion you put it in but also everything else
Re: About the noLoop() and loop(), what do they do?
Reply #4 - Jan 10th, 2010, 12:26pm
 
jeffg is right, noLoop() just changes a flag so that draw() is no longer called (it is called at least once if noLoop() is in setup()).
So, antima55, your usage isn't right. Your function is called repeatedly only if it is called repeatedly, eg. in draw().
So, Cedric, it won't stop everything. It doesn't prevent the program to run. Only to loop on draw().
Re: About the noLoop() and loop(), what do they do?
Reply #5 - Jan 10th, 2010, 12:44pm
 
thats actually what i ment, i guess my post was missleading too Smiley
Re: About the noLoop() and loop(), what do they do?
Reply #6 - Jan 10th, 2010, 2:11pm
 
What about mouse interaction? I always found that if I don't call noLoop() when I pop up a dialog, then the processing stops responding after I hit ok on the dialog, ONLY when the dialog is directly above processing window. If I drag the dialog away so that when I click ok, my click won't be above any processing window, I don't freeze the program. But if I use noLoop() before the dialog, this problem is gone. That makes me think about that noLoop() also disables mouse events and how about keyboard events and other things? I'm trying to minimize and elimate anything that will like crash my program. Thanks.
Re: About the noLoop() and loop(), what do they do?
Reply #7 - Jan 10th, 2010, 2:21pm
 
i guess what i said was a little misleading what i meatn was that you can use the noloop function to avoid loops in draw and in stead use other functions like keypressed or mousepressed to let the use interact.
Re: About the noLoop() and loop(), what do they do?
Reply #8 - Jan 10th, 2010, 3:31pm
 
I think the documentation is fairly clear, but this might help:

Code:
void setup() {
 size(200,200);
 //noLoop();
}

void draw() {
 noLoop();
 println("draw");
}

void mousePressed() {
 println(mouseX + " " + mouseY);
}

void mouseReleased() {
 println("released");
 
}

void mouseDragged() {
 println(mouseX + " " + mouseY);
 line(pmouseX,pmouseY,mouseX,mouseY);
 // redraw();
}

void keyPressed() {
 println(key);
}


Mouse and keyboard events are registered, but nothing is drawn to the screen (see mouseDragged and try it with noLoop() commented out), but as it says:

Quote:
When noLoop() is used, it's not possible to manipulate or access the screen inside event handling functions such as mousePressed() or keyPressed().


So it doesn't explicitly say mouse events etc. aren't registered - simply that they can't do anything with draw() or access draw-related variables...  Perhaps the dialog you use tries to access something draw-related when it is over the sketch surface and when this fails to get a value back it causes a null-pointer exception within the dialog code...
Re: About the noLoop() and loop(), what do they do?
Reply #9 - Jan 10th, 2010, 4:09pm
 
blindfish,

Thanks. I got that part you're demonstrating with the code. For the accessing draw from the dialog, I do not really necessarily access anything. I only display a message dialog, say "Here comes the xxx" with an ok button. When I use noLoop() and loop() to sandwich the dialog, nothing is going wrong and I don't see that the mouse functions I write get executed by the click that presses the ok button on the dialog. If like you said the event is registered, processed but not drawn, yes, but only within processing. If I use some swing elements I don't know the answers anymore. That is what I'm still looking for.
Page Index Toggle Pages: 1