"expecting EOF, found 'filled'" help with making a setting

The goal of the application is to generate a cube graphic and later its going to import settings from a text document that will change the color, size and fill of the cube. Part of this involves making something in the program that will read if one of the settings for the class Block will say either the string "Filled" or not say the string "Filled." I tried to set up a boolean "fill" which is assigned to the cube.fill type in setup = the String "Filled", then it should use the function drawBlockfill for its parameters, but if it says anything other than "Filled," it should use the function drawBlockhollow. As it is I'm getting the EOF error which, according to these forums, there never seems to be a consistent solution to. I'd like to know if the way I'm doing this is possible within the syntax of processing, and if so why isn't it working. If this isn't the way to do it, do you have any suggestions? I'm using processing 3.0. Thanks!

        final int W = 640, H = 480;

        BufferedReader reader;
        Block cube;

        boolean filled;

        filled = cube.fill = "Filled";

        void setup()
        {
          size( 640, 480 );
          cube = new Block();
          cube.x = 200;
          cube.y = 200;
          cube.wi = 120;
          cube.hi = 120;
          cube.c = color(39,200,39);
          cube.fill = "Filled";
        }

        void draw()
        {
            background(255);
            if(filled)
            {
            drawBlockfill(cube);
            }
            else
            {
            drawBlockhollow(cube);
            }
        }

        void drawBlockfill ( Block b )
        {
          noStroke();
            fill(b.c/2);
            rect(b.x, b.y, b.wi, b.hi);
            fill(b.c);
            quad( b.x+b.wi/2, b.y - b.hi/2, b.x + b.wi*1.5, b.y - b.hi/2, b.x + b.wi, b.y, b.x, b.y);
            fill(b.c*2);
            quad( b.x + b.wi, b.y, b.x + (b.wi*1.5), b.y - b.hi/2, b.x + (b.wi*1.5), b.y + (b.hi/2), b.x + b.wi, b.y + b.hi);
        }

        void drawBlockhollow ( Block b )
        {
         noFill();
          stroke(b.c);
            rect(b.x, b.y, b.wi, b.hi);
            noFill();
            stroke(b.c);
            quad( b.x+b.wi/2, b.y - b.hi/2, b.x + b.wi*1.5, b.y - b.hi/2, b.x + b.wi, b.y, b.x, b.y);
            noFill();
            stroke(b.c);
            quad( b.x + b.wi, b.y, b.x + (b.wi*1.5), b.y - b.hi/2, b.x + (b.wi*1.5), b.y + (b.hi/2), b.x + b.wi, b.y + b.hi);
        }

        class Block
        {
            int x, y;
            int wi, hi;
            color c;
            String fill;
        }

Answers

  • edited October 2015

    You're doing things a little weird. This line in particular:

    filled = cube.fill = "Filled";
    

    There's no comparison happening there. You're got two assignments. Did you mean this?

    filled = ( cube.fill == "Filled" );
    

    Because that's better, but still wrong. This is what I think you really want:

    filled = cube.fill.equals("Filled");
    

    But it's in the wrong place - you have it at the global level, where it will be evaluated before cube.fill is assigned a value.

    Here's some code that removes the cube.fill property from the class entirely, and just uses the global boolean filled to determine if the cube should be drawn filled or not:

    //final int W = 640, H = 480;
    
    //BufferedReader reader;
    Block cube;
    
    boolean filled;
    
    void setup()
    {
      size( 640, 480 );
      cube = new Block();
      cube.x = 200;
      cube.y = 200;
      cube.wi = 120;
      cube.hi = 120;
      cube.c = color(39, 200, 39);
      //cube.fill = "Filled";
      filled = true;//cube.fill.equals("Filled");
    }
    
    void draw()
    {
      background(255);
      if (filled)
      {
        drawBlockfill(cube);
      } else
      {
        drawBlockhollow(cube);
      }
    }
    
    void drawBlockfill ( Block b )
    {
      noStroke();
      fill(b.c/2);
      rect(b.x, b.y, b.wi, b.hi);
      fill(b.c);
      quad( b.x+b.wi/2, b.y - b.hi/2, b.x + b.wi*1.5, b.y - b.hi/2, b.x + b.wi, b.y, b.x, b.y);
      fill(b.c*2);
      quad( b.x + b.wi, b.y, b.x + (b.wi*1.5), b.y - b.hi/2, b.x + (b.wi*1.5), b.y + (b.hi/2), b.x + b.wi, b.y + b.hi);
    }
    
    void drawBlockhollow ( Block b )
    {
      noFill();
      stroke(b.c);
      rect(b.x, b.y, b.wi, b.hi);
      noFill();
      stroke(b.c);
      quad( b.x+b.wi/2, b.y - b.hi/2, b.x + b.wi*1.5, b.y - b.hi/2, b.x + b.wi, b.y, b.x, b.y);
      noFill();
      stroke(b.c);
      quad( b.x + b.wi, b.y, b.x + (b.wi*1.5), b.y - b.hi/2, b.x + (b.wi*1.5), b.y + (b.hi/2), b.x + b.wi, b.y + b.hi);
    }
    
    class Block
    {
      int x, y;
      int wi, hi;
      color c;
      //String fill;
    }
    
    void mousePressed(){
      filled = !filled;
    }
    

    Notice also that some other extra stuff here has been commented out - the reader variable you're not using, and the W and H variables.

    But even this way, you're still doing things a little weird.......

  • And what I mean by that is that you have this great Block class, but you're not using it like an object at all. Your drawBlockfilled() and drawBlockhollow() functions can belong to the Block class, as can the filled property.

    class Block {
      int x, y, w, h;
      color c;
      boolean filled;
      Block(int ix, int iy, int iw, int ih, color ic, boolean ifilled) {
        x=ix;
        y=iy;
        w=iw;
        h=ih;
        c=ic;
        filled=ifilled;
      }
      void draw() {
        if (filled) {
          drawFilled();
        } else {
          drawHollow();
        }
      }
      void drawFilled() {
        noStroke();
        fill(c/2);
        rect(x, y, w, h);
        fill(c);
        quad(x+w/2, y-h/2, x+w*1.5, y-h/2, x+w, y, x, y);
        fill(c*2);
        quad(x+w, y, x+w*1.5, y-h/2, x+w*1.5, y+h/2, x+w, y+h);
      }
      void drawHollow() {
        noFill();
        stroke(c);
        rect(x, y, w, h);
        quad(x+w/2, y-h/2, x+w*1.5, y-h/2, x+w, y, x, y);
        quad(x+w, y, x+w*1.5, y-h/2, x+w*1.5, y+h/2, x+w, y+h);
      }
    }
    
    Block block;
    
    void setup() {
      size(640, 480);
      block = new Block(200, 200, 120, 120, color(39, 200, 39), true);
    }
    
    void draw() {
      background(255);
      block.draw();
    }
    
    void mousePressed() {
      block.filled = !block.filled;
    }
    

    Doing it this way lets the Block class deal with it's own drawing, allowing you to have simple logic inside setup() and draw().

Sign In or Register to comment.