Hello all! As part of a larger project, I created a popup window where a user can enter some text (to change their username in a game). I have a String that stores the player’s username and a separate String that stores the entered text. I initialize my typingPlayerName string by setting it equal to “” , and I use the “typingPlayerName = typingPlayerName + key” method to capture the user’s typing. However, Processing keeps storing a null character at the start of the string. Using println to view the user’s entered text displays a strange box glyph character at the front of the user’s typed text.
I think it’s a problem with the way I’m initializing the typingPlayerName string by setting it equal to a null value, but how do you get around this? I need this string to be a global variable because the way I’m drawing the screens for this game, each area/screen is drawn by a different function.
I’ve tried using typingPlayerName.substring(1), and I’ve also creating a nullTestString and then saying:
String nullTestString = "";
if (typingPlayerName.equals(nullTestString) == true) {
typingPlayerName = str(key);
} else {
typingPlayerName = typingPlayerName + str(key);
}
but both of these approaches yield the exact same results – a strange glyph character at the front of the text and an error message in the console that says “No glyph found for the (\uFFFF) character”
Any ideas?
Here’s some sample code. This is part of a much larger project, this is just the keyPressed() function that does the capturing of input text:
boolean editingPlayerName == false;
String typingPlayerName = "";
void keyPressed() {
if (editingPlayerName == true) {
if (key == '\n') {
playerName = typingPlayerName;
typingPlayerName = "";
updatePlayerName();
} else if (key == BACKSPACE) {
typingPlayerName = typingPlayerName.substring(0, max(0, typingPlayerName.length() - 1));
} else {
if(isTypingPlayerNameEmpty == true) {
typingPlayerName = str(key);
} else {
typingPlayerName = typingPlayerName + str(key);
}
}
}
}
void draw() {
if(editingPlayerName == true) {
if(typingPlayerName.equals("") == true) {
isTypingPlayerNameEmpty = true;
} else {
isTypingPlayerNameEmpty = false;
}
}
if(editingPlayerName == false) {
isTypingPlayerNameEmpty = true;
}
}