We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › Simple error but can not resolve, please help!!!!!
Page Index Toggle Pages: 1
Simple error but can not resolve, please help!!!!! (Read 1250 times)
Simple error but can not resolve, please help!!!!!
May 7th, 2010, 9:28am
 
I get syntax error on the following:

   float f1 = (float)(Math.random() * 0.5D + 0.5D);
   if (Math.random() < 0.5D) f1 *= -1.0F;
   float f2 = (float)(Math.random() * 0.5D + 0.5D);

The error reads:

Syntax error on token "f", delete this token
I am a newbie, please help
Re: Simple error but can not resolve, please help!!!!!
Reply #1 - May 7th, 2010, 11:40am
 
You're not on the right forum subject but why do you add 0.5D ?
If you delete all the "D" (for double ?) : it's working.
Re: Simple error but can not resolve, please help!!!!!
Reply #2 - May 7th, 2010, 12:08pm
 
In Java, D doesn't exist, 0.5 is already a double. And in Processing, F isn't necessary. Here, you can write it simply:
  float f1 = random(0.5, 1.0);
  if (random(1.0) < 0.5) f1 *= -1.0;
  float f2 = random(0.5, 1.0);
Re: Simple error but can not resolve, please help!!!!!
Reply #3 - May 7th, 2010, 3:37pm
 
Yes in Java D doesn't exist, try the code that PhiLho gave and that should work easily.
Re: Simple error but can not resolve, please help!!!!!
Reply #4 - May 7th, 2010, 5:46pm
 
Thank you all for replying. Yup, removing the Ds  took care of the error.

Regards
Page Index Toggle Pages: 1