Unexpected token ;

edited October 2013 in Questions about Code
//Thermal Diffusion between fire particles.

class BThermalDiffusion implements BehaviorInterface {
  float effD; //effective distance of diffusion
  float b; //coeffient
  float squaredEffD; // square of effD
  float squaredHalfEffD; // square of half effD

  BThermalDiffusion() {
   this(25.0, 0.2);
  }
  BThermalDiffusion(float x, float y) {
    effD = x;
    b = y;
    squaredEffD = effD*effD;
    squaredHalfEffD = squaredEffD/4;
  }

  void apply(VParticle p) {
    float temp=0.0;
    for(VParticle neighbor : p.neighbors) {
      if(neighbor == p)
        continue;
      float squaredDis = p.distSq(neighbor);
      if(squaredDis <= squaredEffD) 
        temp += neighbor.getTemperature()*b*(1.0-squaredDis/squaredEffD)*exp(-1.0*squaredDis/squaredHalfEffD);
    }
    p.addHeat(temp);
  }
}

Unexpect token : ;. Highlighted the last line. The sketch includes 5 files written by me. Error reported in this file.

Answers

  • Error reported in this file.

    but that's no real guarantee that it's in this file, especially if it's something like a missing {} or ()

    i can't see anything in there myself

  •        //Thermal Diffusion between fire particles.
    
    class BThermalDiffusion implements BehaviorInterface {
      float effD; //effective distance of diffusion
      float b; //coeffient
      float squaredEffD; // square of effD
      float squaredHalfEffD; // square of half effD
    
      BThermalDiffusion() {
       this(25.0, 0.2);
      }
      BThermalDiffusion(float x, float y) {
        effD = x;
        b = y;
        squaredEffD = effD*effD;
        squaredHalfEffD = squaredEffD/4;
      }
    
      void apply(VParticle p) {
        float temp=0.0;
        for(VParticle neighbor : p.neighbors) {
          if(neighbor == p)
            continue;
          float squaredDis = p.distSq(neighbor);
          if(squaredDis <= squaredEffD) 
            temp += neighbor.getTemperature()*b*(1.0-squaredDis/squaredEffD)*exp(-1.0*squaredDis/squaredHalfEffD);
        }
        p.addHeat(temp);
      }
    }
    
    
            //Fire Solo Particle
    
            class FireParticle extends SoloParticle {
              float temperature;
              color fcolor;
              float H; //Heatforce coeffient
              float a; //conservative coeffient <1
              protected float deltaHeat; //heat change rate(heat increment per frame)
    
    
              FireParticle(Vec loc) {
                super(loc);
                this.setRadius(1.0);
                temperature = 850.0;
                fcolor = color(255, 204, 0);
                a = 0.8;
                H = 0.02;
                deltaHeat = 0.0;
              }
    
               /*protected color colorCaculate() {
                 return new color c(#FFCC00);
              }*/
    
               protected void updateTemperature() {
                temperature *= a;
                applyHeat();
              }
    
              void addHeat(float h) {
                deltaHeat += h;
              }
    
              protected void applyHeat() {
                temperature += this.deltaHeat;
                deltaHeat = 0.0;
              }
    
             //Fire particle has a intern asending force caused by temperature. need to override appleForce().  
               protected void applyForce() {
                           force.addSelf(new Vec(0, H*temperature));
                    temp.set(this);
    
                    addSelf(sub(prev).addSelf(force.mult(weight)));
                    prev.set(temp.copy());
    
                    force.clear();
                }
    
              float getTemperature() {
                return temperature;
              }
            }
    
    
              //Particle syetem of fire
    
        class FireSystem extends ParticleSystem {
          int fuel; //fuel type determines mapping function relationship between color and temperature
    
          FireSystem(Vec loc, int num, int f) {
            super(loc, num);
            fuel = f;
          }
    
          //override addParticle() to add Thermal Diffusion
          void addParticle(FireParticle f) {
          super(f);
          f.addBehavior(new BThermalDiffusion());
          }
    
        }
    
        //FireSimulation
    
        import punktiert.math.*;
        import punktiert.GPUPhysics.*;
        import punktiert.physics.*;
    
        FireSystem ps;
    
        void setup() {
          size(640, 360);
          colorMode(RGB, 255, 255, 255, 100);
          ps = new FireSystem(new Vec(width/2,height/2), 20, 1);
          smooth();
          frameRate(50);
        }
    
        void draw() {
          background(0);
          ps.run();
          ps.addParticle(new FireParticle(new Vec(mouseX,mouseY)));
        }
    

    Above should be the whole picture. 3 files(unfinished) to simulate fire effect by particle systems. I made some tiny changes, so some code in BThermalDiffusion are a little different from previous edition. And, I still get "Unexpected token" error. Have been checking this the hole night. Plz help!

  • nope, i pasted it into a decent java editor and reformatted it and still can't see anything wrong with it.

    are any of the files java files rather than processing files? if so you might need to follow proper java conventions like not using the color type or defining floats with a trailing f, ie 0.0f

    also, it's good practice to put {}s around even single line blocks, makes it more readable. the seconds you save with the typing aren't worth the extra debugging time in my experience...

  • edited October 2013

    fwiw, i get a different error:

    unexpected token: (

    on line 100

    but i don't have those libraries

  • I got error on line 120;--super(f);

     void addParticle(FireParticle f) {
      super(f); //<-----**unexpected token: (**
      f.addBehavior(new BThermalDiffusion());
      }
    
  • and call for ps.run() ? why? ps [object of firesystem class]

  • The super() syntax is usable only in constructors.
    Otherwise, you have to use the syntax:

    super.addParticle(f);
    

    No idea for ps.run(), because you don't tell us what error you have, and we don't know what the ParticleSystem class looks like.

  • edited October 2013

    or he might be not writing super(param) method in the super class. or forget written that. he had the method, super(param1,param2); in the ps object, there is no run(). may be he wish to run a thread?

  • Thx all! guys! problem solved aly. It turns out some of my other files containing logic error.

Sign In or Register to comment.