по какой-то причине я могу сделать практически любой метод для строки. Это включает в себя:Java все методы работают для строки, за исключением возврата строки
* Получение длины строки
* Добавление к строке
* Использование подстроки
* И, наверное, everythng еще
Кроме этого, я не могу получить значение строки, за исключением случаев использования моего метода drawString
для рисования на экране в lwjgl. Вот мой код, прежде чем я объясню проблему.
public static boolean chatOn = false;
public static String text = "";
public static float typetimer = 0;
public static int ctrltimer = 0;
public static boolean runcmd = false;
public static void chat() {
if (Keyboard.isKeyDown(Keyboard.KEY_TAB)) {
if (ctrltimer < 0) {
chatOn = !chatOn;
Keyboard.destroy();
try {Keyboard.create();} catch (LWJGLException e) {}
ctrltimer = 10;
}
}
ctrltimer -= Game.delta;
typetimer -= Game.delta;
if (chatOn) {
//try {text.replace(null, "happy");} catch(NullPointerException e) {}
System.out.println(text);//print to console, dosen't
Text.drawString(text, 0, 0);//write the text on the screen with my draw method, does work
System.out.println(text);//print to console, dosen't, yet the one drawstring worked
if (typetimer < 0) {
while (Keyboard.next()) {
try {
if (Keyboard.getEventKey() == Keyboard.KEY_BACK) {
text = text.substring(0, text.length()-1);
typetimer = 1;
System.out.println(text);//print to console, doesn't
}
else if (Keyboard.getEventKey() == Keyboard.KEY_RETURN) {
System.out.println(text);//print to console, doesn't
runCommand();
text = "";
chatOn = false;
}
else {
System.out.println(text);//print to console, doesn't
text = text + Keyboard.getEventCharacter();
}
typetimer = 10;
} catch(Exception e){
}
}
}
}
}
public static void runCommand() {
String command = text;
System.out.println(command);//print to console, doesnt
if (command.startsWith("time")) {
try {
String[] time = new String[1];
time = command.split(" ", 0);
Camera.nighttimeASecond = Integer.parseInt(time[0]);
} catch (Exception e){
System.out.println("could not set time");
}
}
}
Если вы читали мои заметки внутри кода вы можете увидеть, где я поставил print
метод и drawString
метода. Методы print
ничего не печатают и иногда могут печатать первые несколько слов строки, хотя метод drawString
работал нормально. Спасибо - Tyler
Вы пробовали отлаживать, чтобы узнать, что на самом деле происходит? – t0mppa
Да, я пытаюсь отладить его некоторое время. есть ли у вас какие-либо трюки, чтобы помочь отладить его? –
Я имел в виду установку контрольной точки, остановку выполнения, проверку содержимого переменной при ее печати и в том, что происходит в методе 'drawString'. Очевидно, значение переменной не просто волшебным образом может измениться само по себе, поэтому должно быть что-то влияющее на нее. – t0mppa