hex(get()) not working

edited March 2016 in Questions about Code

I am getting an error with this

String colorSensing(){
  color ycolor=get(x,y+51);
  if (hex(ycolor)==#FFFFFF){
    return "white";
  }
}

Could someone tell me whats wrong? Thank you!

Tagged:

Answers

  • edited March 2016 Answer ✓

    hex() returns a String

    you are comparing that with #FFFFFF which is actually an int(?) (try println(#FFFFFF) and see what it does).

    you could try hex(color).equals("#FFFFFF")... it might work...

    actually, ycolor == #FFFFFF might also work

    (not in a position to test, sorry)

  • edited March 2016 Answer ✓

    if ("FFFFFF".equals(hex(ycolor, 6))) return "white";

    String colorSensing(int x, int y, int yOffset) {
      final color c = get(x, y + yOffset);
      final String webColor = hex(c, 6);
    
      switch (webColor) {
      case "FFFFFF":    
        return "white";
      default: 
        return "unknown";
      }
    }
    
  • Thanks guys!

Sign In or Register to comment.