코드를 실행하면 "일치하지 않는 문자가 너무 많습니다"라는 오류 메시지가 표시되지만 체크하고 다시 확인한 후, 재검사하고 심지어 누군가 다른 사람이 나를 확인해 주었다.처리 중 중괄호에 문제가 있음
class Ball {
//Global Vars
//float x=0;
//float y=0;
//float speedx = random(-5,5);
//float speedy = random(-1,1);
Vec3D loc = new Vec3D (0, 0, 0);
Vec3D speed = new Vec3D (random(-4, 4), random(-1, 1), 0);
Vec3D acc = new Vec3D();
Vec3D grav = new Vec3D (0, random(0.05, 0.25), 0);
//construct
Ball(Vec3D _loc) {
loc = _loc;
}
//functions
void run() {
display();
move();
bounce();
// gravity();
lineBetween();
flock();
}
void display() {
stroke(0);
ellipse(loc.x, loc.y, 20, 20);
}
void move() {
// x += speedx;
// y += speedy;
speed.addSelf(acc);
speed.limit(6);
loc.addSelf(speed);
acc.clear();
}
void bounce() {
if (loc.x > width) {
speed.x = speed.x*-1;
}
if (loc.x < width-width) {
speed.x = speed.x*-1;
}
if (loc.y > height) {
speed.y = speed.y*-1;
}
if (loc.y < height-height) {
speed.y = speed.y*-1;
}
}
void gravity() {
//speedy += 0.15;
speed.addSelf(grav);
}
void lineBetween() {
//ballCollection
for (int i=0; i<ballCollection.size();i++) {
Ball other = (Ball) ballCollection.get(i);
float distance = loc.distanceTo(other.loc);
if (distance > 0 && distance < 80) {
stroke(255, 0, 255);
strokeWeight(0.2);
line(loc.x, loc.y, other.loc.x, other.loc.y);
}
}
}
void flock() {
separate();
// cohesion();
// align();
}
void separate(float magnitude) {
Vec3D steer = new Vec3D();
int count = 0;
for (int i=0; i<ballCollection.size();i++) {
Ball other = (Ball) ballCollection.get(i);
float distance = loc.distanceTo(other.loc);
if (distance > 0 && distance < 40) {
Vec3D diff = loc.sub(other.loc);
diff.normalizeTo(1.0/distance);
steer.addSelf(diff);
count++;
}
}
}
if (count>0) {
steer.scaleSelf(1.0/count);
}
steer.scaleSelf(magnitude);
acc.addSelf(steer);
}
오류 메시지는 106 행을 강조 표시합니다.
if (count>0) {
다른 컴퓨터에서 오류를 다시 작성했지만 문제없이 튜토리얼 비디오에 사용 된 코드를 보았습니다. 모든 도움을 크게 주시면 감사하겠습니다 :)
당신은 .. ?? 이클립스와 같은 IDE를 사용 : 나는 그들이 이러한 문제를 방지하기 위해 '말'중괄호를 언급 나의 프로그래밍 학생들에게 제안 코드를 포맷하는 것 .. 그렇지 않으면 메모장 ++을 사용할 수도 있습니다. 일반 txt 파일에 코드를 작성하는 것을 피하십시오 ... 포맷되지 않은 코드는 읽기가 어려울 것입니다 .. – TheLostMind
저는 처리 편집기에서 정기적으로 자동 서식을 지정합니다. CTRL + T : – BenjiHare
이것이 해결되었다는 것을 알았지 만, PDE X (나는 그것이 무엇이라고 불렀는지)를 사용하여 플라이 코드 완성과 구문 검사를 할 수 있습니다. 아직 베타 버전이지만 다음 프로세싱 IDE 일명 PDE : P가 될 것입니다. 여기에 몇 가지 정보가 있습니다 : http://www.mkmoharana.com/2013/09/announcing-pde-x.html –