Loading...
Logo
Processing Forum
Hello, I've written a program (or have attempted to) that types out random quotes in my bank of quotes below. Can anyone tell me what might be causing the "expecting LPAREN, found 'mousePressed' " error?

much appreciated!

Copy code
  1. PFont f;
  2. void setup() {
  3.   size(400,200);
  4.   f = createFont("Arial",16,true);
  5. }
  6. void draw() {
  7.   background(255);
  8.   textFont(f);      
  9.   fill(0);
  10.   textAlign(CENTER);
  11.   text("A Collection of Inspirational Quotes",width/2,80);
  12.  
  13.   if mousePressed() {
  14.   int r = (int)random(8);
  15.  
  16.   if(r==0){
  17.   text("Try not to become a man of success but a man of value.",width/2,80);
  18.   text("Albert Einstein", width/2,95);
  19.   }
  20.   else if(r==1){
  21.   text("Inspiration and genius--one and the same.",width/2,80);
  22.   text("Victor Hugo", width/2,95);
  23.   }
  24.   else if(r==2){
  25.   text("Every artist was first an amateur.",width/2,80);
  26.   text("Ralph Waldo Emerson", width/2,95);
  27.   }
  28.   else if(r==3){
  29.   text("No great man ever complains of want of opportunities.",width/2,80);
  30.   text("Ralph Waldo Emerson", width/2,95);
  31.   }
  32.   else if(r==4){
  33.   text("The power of imagination makes us infinite.",width/2,80);
  34.   text("John Muir", width/2,95);
  35.   }
  36.   else if(r==5){
  37.   text("You miss 100% of the shots you don't take.",width/2,80);
  38.   text("Wayne Gretzky", width/2,95);
  39.   }
  40.   else if(r==6){
  41.   text("It always seems impossible until it's done.",width/2,80);
  42.   text("Nelson Mandela", width/2,95);
  43.   }
  44.   else if(r==7){
  45.   text("An ounce of practice is worth more than tons of preaching.",width/2,80);
  46.   text("Gandhi", width/2,95);
  47.   }
  48.   else if(r==8){
  49.   text("Winning is habit. Unfortunately, so is losing.",width/2,80);
  50.   text("Vince Lombardi", width/2,95);
  51.   }
  52. }

Replies(2)

Hi kriotos,

what about:

Copy code
  1. if (mousePressed == true)

Greetings!

In Java, you must have parentheses around the conditional of a if, even if there is only one element.
So that's:
if (mousePressed) {
at line 13.
Not mousePressed() which is a function you must not call (that's Processing which calls it).