Hi I’m making a game and I need some help with a true/false line. I need picture to load when a specific key isn’t pressed (the key is ENTER).
your inverted logic is not fully clear,
but the inverted function of keyPressed would be keyReleased
like in " is not pressed any more "
somehow i doubt that is what you want.
also you possibly want toggle something at ENTER Released??
boolean my_stat = true;
void setup() {}
void draw() {}
void keyReleased(){
if ( keyCode == ENTER ) { my_stat = !my_stat; println("my_stat: "+my_stat);} }
here’s an example
void draw() {
if (!keyPressed) {
if (key == 'b' || key == 'B') {
fill(0);
}
} else {
fill(255);
}
rect(25, 25, 50, 50);
}
the square should be black when b isn’t pressed but it is white in the start for some reason. it is important “!” is used in this case
where you detect the operation of the ENTER key?
just Imagine b is ENTER in this case.
if you want debug some code it helps to use
println("something: "+something);
i can’t see how that’s gonna help me.
i used the example
and changed to !keyPressed and it works here,
( like at the second time )
also shift key is a problem
anyhow you could never use in combination with other key detect
// Click on the window to give it focus,
// and press the 'b' key.
void draw() {
if (!keyPressed) {
if (key == 'b' || key == 'B') {
fill(0);
}
} else {
fill(255);
}
rect(25, 25, 50, 50);
}
so just not do it that way.
test
// Click on the window to give it focus,
// and press the 'B' key.
int k = 0;
void draw() {
if (!keyPressed) {
if (key == 'b' || key == 'B') {
k++;
println("k: "+k+" key: "+key);
fill(0);
}
} else {
fill(255);
}
rect(25, 25, 50, 50);
}
to actually see what you are doing
ty i think i have solved it