boolean in combination with if-loop: how to make it do it only once..
in
Programming Questions
•
3 years ago
- import napplet.*;
NAppletManager nappletManager; - boolean a=false;
void setup()
{nappletManager = new NAppletManager(this);
size(200,200);
}
void draw(){
if(mousePressed==true&&mouseX>20)
{mpressed();}
if (a){
nappletManager.createWindowedNApplet("button1a",0,0);
a=!a;
}
}
void mpressed(){
a=true;
}
This code is with napplet but that doesn't matter.. It's the problem of "repetition". NoLoop() doesn't work because I have to repeat it and I can't set it on loop() after done it..
My problem is, that this program opens a new window three times, I'd like to do it once.. It's no problem with no if-loop but this way I couldn't work it out..
FrameRate(10); for example works.. but then if I press the mouse for a longer time, the window is still opened endless times..
My problem is, that this program opens a new window three times, I'd like to do it once.. It's no problem with no if-loop but this way I couldn't work it out..
FrameRate(10); for example works.. but then if I press the mouse for a longer time, the window is still opened endless times..
No matter how long the button is pressed (here the mouse with mousex-position>20), the window should only be opened once (and if the window is opened and the button is pressed again, the window shouldn't be opened again).
The same problem I've got with creating some objects of a class. When I want to create automatically ONE point if the button is pressed, it creates the same point three times..
I did it once with controlp5 and don't know why but that worked..
I'm confused.. and stuck with it..
I'm confused.. and stuck with it..
thanks..
1
