2013-02-21 1 views
2

가상 애완 동물 게임을 만들고 있습니다. 이 단계에서는 저장 파일을로드했지만 핵심 기능을 포함하기 시작하면 프로그램이 실행되지 않습니다.처리 오류 : 잘못 구성된 문자 상수 (예상 상한값, 예상치)

찾았습니다. Badly formed character (expecting quote, got I) ~ Processing 내로드 기능에 문제가 있다고 생각합니다. 그러나 처리가 새로 생겼고이를 디버깅하는 방법을 모르겠습니다.

Creature creature; 
String data[]; 
boolean gameInfo[]; 
int tempData[]; 
boolean food; 

void setup() { 
    size(100,100); 
    String data[] = loadStrings("save.txt"); 
    String[] tempData = split(data[0], ','); 
    gameInfo = int(tempData); 
    for (int i = 0; i < data.length; i++) { 
    creature = new Creature(gameInfo[0], gameInfo[1], gameInfo[2], gameInfo[3]); 
    } 
    food = false; 
} 

void draw() { 
    creature.think(food); 
} 

//creature class 

class Creature { 
    boolean idle; 
    int hungry; 
    int age; 
    int gender; 
    int asleep; 


    Creature(int gender, int age, int hungry, int asleep) { 
    this.gender = gender; 
    this.age = age; 
    this.hungry = hungry; 
    this.asleep = asleep; 
    boolean idle = true; 
    } 
    void whatDo(boolean food) { 
    println('whatdo'); 
    if (idle = true && hungry == true) { 
     if (food == true) { 
     creature.eat(); 
     } 
     else 
     creature.ask(); 
    } 
    } 

    void ask() { 
    if (hungry == true) { 
     println("HUNGRY"); 
    } 
    } 
    void eat() { 
    println("EAT"); 
    idle = false; 
    } 
} 
+0

'if (idle = true && hungry == true)'아마도 유휴 상태 == true를 의미했을 것입니다. 그렇지 않습니까? –

+0

예, 두 번째 아이콘이 게시됨을 알게되었습니다. 이제 변경되었습니다. 그럼에도 불구하고 고맙습니다. – glocka

답변

2

글쎄, 당신이 가리키는 링크가 설명 하듯이, 문제가)가 'c', 그리고에 println (같은 두 개의 작은 따옴표 사이에 문자가 될 수 갈까요 있도록 작은 따옴표 문자 할당을위한 것입니다 예상하는 문자열 느릅 나무는 정의 큰 따옴표 사이에 "a string". 40 번 줄의 println('whatdo');println("whatdo"); (큰 따옴표)로 바꾸면이 오류가 제거됩니다. 하지만 나는 그것을 고치면 다른 사람들이 실수를하게된다.

+0

도와 주셔서 대단히 감사합니다. – glocka

+0

프로그램 개발 방법에 관심이 있으시면 http://stackoverflow.com/questions/15015560/get-value-from-an-arraylist-of-objects-processing에 다시 게시했습니다. – glocka

관련 문제