I’m having issues with keyboard not being read. At first, I though my issues were Draw() not looping (or not ending before next loop), but it seems Draw() is running at good fps rate.
My project has a complicate structure, and Draw() is divided this way:
void draw(){
switch (status){
case INTRO:
drawIntro();
break
case FIRST:
drawFirstLevel();
/* and so on */
}
}
Also, keyPressed() is also divided in a similar way, so I have just one goUp() routine for both keyCode “UP” and Key ‘W’ (and so on).
The case is status should go from INTRO to FIRST when ANY key is pressed, but it never changes.
The issue arosed randomly on previous stages of code, but now it is persistent. The main change was adding a big list of loadImages on a sideloading thread().
Any idea on how to debug?
Is keyPressed() triggered when loading a function from Draw, or should I keep all code inside of Draw to make sure keyPressed() is checked?
And this is the complete keypressed and related functions.
Please notice there are many “while” instructions inside. Some hours after my last message I thought the problem could be related to these “while” instructions, but after doing some sanitizing inside, the problem persists.
void keyPressed() {
if (waitKeyAny|status==STATUSINTRO) {
println("Any key Pressed"+status);
if (status==STATUSINTRO) status=STATUSFLOOR;
return;
}
println("Keypressed");
if (key!=CODED) {
/* CODED (ASCII) KEY USED */
switch(key) {
case 'W':
case 'w':
case '8':
doUp();
break;
case 'S':
case 's':
case '2':
doDown();
break;
case 'A':
case 'a':
case '4':
myX--;
/* If maxX==0 this causes infinite loop */
if (maxX>0) {
while (myX<0) myX+=maxX;
} else {
myX=0;
}
break;
case 'D':
case 'd':
case '6':
// 84/16=5.25
if (maxX>0) myX=(myX+1)%maxX;
break;
case ' ':
case RETURN:
case 5:
/* SELECTION -- Decide what to do */
if ( (status & STATUSDIALOG)!=0) dialogReturn();
break;
case (char) 27:
/* ESCAPE */
doEscape();
}
} else {
/* KEYCODE USED */
switch(keyCode) {
case UP:
doUp();
case DOWN:
// 48/16=3
doDown();
break;
case LEFT:
myX--;
/* If maxX==0 this causes infinite loop */
if (maxX>0) {
while (myX<0) myX+=maxX;
} else {
myX=0;
}
break;
case RIGHT:
// 84/16=5.25
if (maxX>0) myX=(myX+1)%maxX;
break;
case 4:
/* BACK ANDRODID BUTTON: Exit form mode */
doEscape();
break;
}
}
}
/* Processes "UP" key:*/
void doUp() {
if (status==STATUSFLOOR) {
int selDoor=int(1+myX/32) % 8;
if (piso[myFloor][selDoor].rtype==HSTAIRS) {
if (myFloor<8) {
myFloor++;
}
}
} else {
myY--;
/* If maxY<0 this causes infinite loop */
if (maxY>0){
while (myY<0) myY+=maxY;
}
}
}
void doDown() {
if (status==STATUSFLOOR) {
int selDoor=int(1+myX/32) % 8;
if (piso[myFloor][selDoor].rtype==HSTAIRS) {
if (myFloor>0) {
myFloor--;
} else {
status=STATUSDIALOG | STATUSFLOOR;
dialognum=CONFIRM_EXIT;
storeFloorX=myX;
myX=0;
maxX=1;
maxY=1;
}
}
} else {
if (maxY>0) myY=(myY+1)%maxY;
}
}
/* Process Escape. I.E. Exit from a Dialog */
void doEscape() {
if ((status & STATUSDIALOG)!=0) {
switch (status ^STATUSDIALOG) {
case STATUSFLOOR:
// XOR StatusDIALOG bit
status^=STATUSDIALOG;
if (status==STATUSFLOOR) {
myX=storeFloorX;
}
break;
}
}
}
void dialogReturn() {
switch (dialognum) {
case CONFIRM_EXIT:
if (myX==0) {
status=STATUSEXITGAME;
return;
} else {
// XOR StatusDIALOG bit
status^=STATUSDIALOG;
if (status==STATUSFLOOR) {
myX=storeFloorX;
}
}
break;
}
}
REMOVING println() lines inside draw() showed keypress was working (but their printlns were hidden by the many printlns inside keyPress).
@JoseMY
Hey,
I am curious if you’ve used in that project some library/class to drive Nokia (5110?) display from Processing by any chance? I’m trying to google something without luck so far…
Sorry, I did not put a 5110 screen driver in processing. I merely made a filter to turn a black-and-white screen into colors that resemble those of Nokia 5110.
I was entering a Nokia jam in itch.io. That is a yearly jam. If you are interested, look for nokia jam in itch.io.