Unexpected Unexpected token: 8

edited June 2015 in Questions about Code

Hi! I'm writing a really simple program to denote a certain dataset in colors. I'm sure there is a more elegant way to do this, but at this point, I'm trying to split the months across three categories (months Jan through April is blue, May through August is Yellow, and Sept through December is green). It seems to be working perfectly, until I insert month[i]==08. It returns unexpected token: 8. Any suggestions?

Table pdd;
String file ="data/somedatahere.tsv";
int year[];
int month[];
int downloads[];
int rows;
color white = color(255, 255, 255);
color blue = color(29, 145, 192);
color yellow = color(250, 187,12);
color green = color(70,138,7);
color mix;

void setup() {
  //size & margins
  size(1400, 800);
  int lmargin = 50;
  int tmargin = 50;
  int canvaswd= (width-(2*lmargin));

  //load & parse file
  pdd=loadTable(file,"header");
  rows= pdd.getRowCount();
  println(rows);

  year= new int[rows];
  month= new int[rows];
  downloads= new int[rows];

  for (int i=0; i<rows; i++){
  TableRow row= pdd.getRow(i);
  year[i]=row.getInt("YY");
  month[i]=row.getInt("MM");
  downloads[i]=row.getInt("Downloads");
  }
}

void draw(){
  background(0);
  int lmargin=50;
  int tmargin=50;

  for(int i=0; i<rows; i++){
     float amt = map(downloads[i], 3974, 178736, 0, 1); 
    if(month[i]==01 ||month[i]==02 || month[i]==03 ||month[i]==04 ){
  mix = lerpColor(white, blue, amt);
 } else if (month[i]==05 || month[i] ==06 || month[i]==07){
 mix =lerpColor(white,yellow,amt);
 } 
   else {
  mix = lerpColor(white, green, amt);}
   fill(mix);
  rect(lmargin+lmargin*0.2*i,(height-tmargin)/2,10,10);
  }
 }

Answers

  • edited June 2015

    Ha! Good one. Try running this:

    println( 00 );
    println( 05 );
    println( 06 );
    println( 07 );
    println( 017 ); // Hmm? 15?
    println( 8 ); // That's ok.
    // println( 08 ); // ERROR! CAN YOU SEE WHY?
    

    Numbers that start with 0 are in octal, or base 8. For 01 to 07, this is the same as 1 to 7. But 08 doesn't make sense in octal, since the number after 07 is 010!

    Just leave off the leading zeros and everything will be fine.

  • Thank you! :)

Sign In or Register to comment.