Code trouble, it thinks something is wrong with the brackets. (Also how check for multiple char?)
in
Programming Questions
•
2 years ago
This is the problem section, it thinks "unexpected token: {" when there's no brackets out of place :( I've gone over it like 20 times
char lastChar = entered.charAt(entered.length()-1 );
if (lastChar == '?') {
lastChar = entered.charAt(entered.length()-3);
}
if (lastChar == ('a', 'b', 'c', 'd') { // WHYTHEFUCK CAN'T I USE MULTIPLE LETTERS?!?!
fill(0,255,0); text("YES", 300, 200);
}
else {
text("NO", 300, 200);
}
// } this is the only off bracket, for the void draw
*********************************************************************************************************
if (lastChar == ('a', 'b', 'c', 'd') //This doesn't work... anyone know the right way?
Entire Code below, thanks for your time either way. (God it's messy in this format)
********************************************************************************************************
PFont z;
String USERINPUT=" ";
String entered = " ";
void setup() {
size(1000,500);
z = createFont("Arial",20,true);
}
void draw() {
background(0);
stroke(255); //Outline color
textFont(z, 30); //and color it
fill(255);
int x = 75; //First char is at 75
text("Simple AI protocol, ask a yes or no question (Type and press enter)", 30, 30);
text(USERINPUT,50,90);
text(entered,200,130);
char lastChar = entered.charAt(entered.length()-1 ); //lastChar = last charachter entered, returns: StringIndexOutOfBoundsException: String index out of range: whatever number the string is long//
if (lastChar == '?') { //if it's a ? then go to the second to last char //CANNOT CONVERT FROM CHAR TO BOOLEAN //once == is made, incompatible operand types char and string, // meaning it needs to be single quotes 'a' NOT "a"
lastChar = entered.charAt(entered.length()-3); //remember, it starts counting at 0, so -1 is the last, -2 is secondToLast (-3 to skip the shift keypress
}
if (lastChar == ('a') { //, WHYTHEFUCK CAN'T I USE MULTIPLE LETTERS?!?!
fill(0,255,0); text("YES", 300, 200);
// if (lastChar == ('') {return:}It should not start with No on the screen
}
else {
text("NO", 300, 200);
}
} //and when it decides there's an "Unexpected token: { bracket for no reason....
void keyPressed() {
if (key == '\n' ) { // If the return key is pressed, save the String and clear it \n = newline
entered = USERINPUT; // A String can be cleared by setting it equal to ""
USERINPUT = "";
} else {
// Otherwise, concatenate the String
// Each character typed by the user is added to the end of the String variable.
USERINPUT = USERINPUT + key;
}
}
char lastChar = entered.charAt(entered.length()-1 );
if (lastChar == '?') {
lastChar = entered.charAt(entered.length()-3);
}
if (lastChar == ('a', 'b', 'c', 'd') { // WHYTHEFUCK CAN'T I USE MULTIPLE LETTERS?!?!
fill(0,255,0); text("YES", 300, 200);
}
else {
text("NO", 300, 200);
}
// } this is the only off bracket, for the void draw
*********************************************************************************************************
if (lastChar == ('a', 'b', 'c', 'd') //This doesn't work... anyone know the right way?
Entire Code below, thanks for your time either way. (God it's messy in this format)
********************************************************************************************************
PFont z;
String USERINPUT=" ";
String entered = " ";
void setup() {
size(1000,500);
z = createFont("Arial",20,true);
}
void draw() {
background(0);
stroke(255); //Outline color
textFont(z, 30); //and color it
fill(255);
int x = 75; //First char is at 75
text("Simple AI protocol, ask a yes or no question (Type and press enter)", 30, 30);
text(USERINPUT,50,90);
text(entered,200,130);
char lastChar = entered.charAt(entered.length()-1 ); //lastChar = last charachter entered, returns: StringIndexOutOfBoundsException: String index out of range: whatever number the string is long//
if (lastChar == '?') { //if it's a ? then go to the second to last char //CANNOT CONVERT FROM CHAR TO BOOLEAN //once == is made, incompatible operand types char and string, // meaning it needs to be single quotes 'a' NOT "a"
lastChar = entered.charAt(entered.length()-3); //remember, it starts counting at 0, so -1 is the last, -2 is secondToLast (-3 to skip the shift keypress
}
if (lastChar == ('a') { //, WHYTHEFUCK CAN'T I USE MULTIPLE LETTERS?!?!
fill(0,255,0); text("YES", 300, 200);
// if (lastChar == ('') {return:}It should not start with No on the screen
}
else {
text("NO", 300, 200);
}
} //and when it decides there's an "Unexpected token: { bracket for no reason....
void keyPressed() {
if (key == '\n' ) { // If the return key is pressed, save the String and clear it \n = newline
entered = USERINPUT; // A String can be cleared by setting it equal to ""
USERINPUT = "";
} else {
// Otherwise, concatenate the String
// Each character typed by the user is added to the end of the String variable.
USERINPUT = USERINPUT + key;
}
}
1