if I'm in the draw and I want to execute an istructions only once
Please provide more information. Some approaches, depending on what you are trying to do:
Write a simple sketch without a setup and draw loop
Execute instructions only once in setup(), before draw() starts
Use noLoop() so that draw() only runs once
To have something only happen once on a specific draw frame or at a specific time, put an instruction in draw() inside an if() statement. There are many ways of doing this -- such as checking a global variable, or checking millis() or frameCount();
A simple sketch:
println("run only once");
Run during setup:
void setup(){
println("run only once");
}
void draw(){}
Run with noLoop: [added]
void setup(){
noLoop();
}
void draw(){
println("run only once");
}
Run on frame 100:
void draw(){
if(frameCount==100){
println("run only once");
}
}
Answers
Easy
When you mean a 2D grid / 2D array:
Make a new function that returns boolean named allCellsAreTrue :
boolean allCellsAreTrue() {
double/ nested for loop over the grid
Inside of it: if(!matrix [i][j] )
after both loops (!!!) :
return true;
The ! means not
so as soon as we hit one cell that's false, we leave the function
Only after testing ALL cells we return true
ok thank you, another thing, if I'm in the draw and I want to execute an istructions only once, as I do?
Please provide more information. Some approaches, depending on what you are trying to do:
setup()
, beforedraw()
startsnoLoop()
so thatdraw()
only runs oncedraw()
inside anif()
statement. There are many ways of doing this -- such as checking a global variable, or checking millis() or frameCount();A simple sketch:
Run during setup:
Run with noLoop: [added]
Run on frame 100:
Run once only:
Run once only after 10 seconds:
thanks you so much
see also noLoop()