Something doesn't work with my string variable
Hello, I need help:
I created a string (vword) and when the game is running I can edit it writing any letter of the alphabet...
When I press Enter and the string is equal to "Hello" it should do something
but it doesn't work!
Can someone help me? Thanks!
(I thought that pressing ENTER I add a character to the string, so it wasn't "Hello" anymore... May this be right?)
=====================================================
String vword = ""; // That's the text
void setup() {
size(400, 300);
}
void draw() {
background(0);
fill(255);
text(vword, 16, 16); // Writes the string vword
}
void keyPressed() {
if (key >= 'A' && key <= 'z') {
vword += key; // I can edit vword writing any letter of the alphabet
}
if (key == ENTER) { // When I press enter...
if (vword == "Hello") { // if i wrote "Hello"
println("oh hi"); // write in console "oh hi"
} else {
println("why don't you say Hello?"); // write in console "why don't you say Hello?"
}
vword = ""; // vword returns blank
}
}