EDIT: My problem was solved. :)
But I have a doubt, what is the most effective way to wait for something to happen in java?
for example, if I want to wait for a boolean b to be true, does this below work?

while(!b) {}
//stuff to do after wait here

or is it more effective to use a Thread and sleep some time before checking again? Or is there another way?

OLD SOLVED STUFF:
Hey, I'm developing a game in which you control a ball with your mouse and you must avoid hitting some rectangles that keep rising in number. While trying to write the scores to a file, I came across a very strange problem. When I add some lines in my code, to wrtie the score to a file, the collision detection stop working!!

EDIT: My problem was solved. :)
But I have a doubt, what is the most effective way to wait for something to happen in java?
for example, if I want to wait for a boolean b to be true, does this below work?

while(!b) {}
//stuff to do after wait here

or is it more effective to use a Thread and sleep some time before checking again? Or is there another way?

OLD SOLVED STUFF:
Hey, I'm developing a game in which you control a ball with your mouse and you must avoid hitting some rectangles that keep rising in number. While trying to write the scores to a file, I came across a very strange problem. When I add some lines in my code, to wrtie the score to a file, the collision detection stop working!!

I think the most effective way to make a program wait is using handling EVENTS..

when a variables's value changes does it create an event, if so, what could I use to detect it?

when a variables's value changes does it create an event, if so, what could I use to detect it?

Change in value of variables does not create a event .

But every GUI application can be well handled through events..

However ,in case of non-GUI application

Instead of checking the value of variable again and again

write the code which you need to execute when a variable value is changed and

call that function when the value changes.

check this condition

if(b==true)
{
valueChanged();
}

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.