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 › How do you make increments greater than 1
Page Index Toggle Pages: 1
How do you make increments greater than 1 (Read 185 times)
How do you make increments greater than 1
Nov 25th, 2008, 10:55pm
 
I would like to make a variable increase by 15 each time. How do I do this?

I've tried instead of:
countZ++;

writing:
countZ + 15;

but was unsuccessful. I also tried this:
if (countZ < imagesB.length * 15) {
 countZ + 15;
}

Which didn't work either.

I have this rather unwieldy section of code:
   image(imagesB[countB + 1], xpos - 15, ypos + 400);
   image(imagesB[countB + 2], xpos - 30, ypos + 400);
   image(imagesB[countB + 3], xpos - 45, ypos + 400);
   image(imagesB[countB + 4], xpos - 60, ypos + 400);
   image(imagesB[countB + 5], xpos - 75, ypos + 400);
   image(imagesB[countB + 6], xpos - 90, ypos + 400);
   image(imagesB[countB + 7], xpos - 105, ypos + 400);
   image(imagesB[countB + 8], xpos - 120, ypos + 400);
   image(imagesB[countB + 9], xpos - 135, ypos + 400);
   image(imagesB[countB + 10], xpos - 150, ypos + 400);
   image(imagesB[countB + 11], xpos - 165, ypos + 400);
   image(imagesB[countB + 12], xpos - 180, ypos + 400);
   image(imagesB[countB + 13], xpos - 195, ypos + 400);
   image(imagesB[countB + 14], xpos - 210, ypos + 400);
   image(imagesB[countB + 15], xpos - 225, ypos + 400);
   image(imagesB[countB + 16], xpos - 240, ypos + 400);
   image(imagesB[countB + 17], xpos - 255, ypos + 400);
   image(imagesB[countB + 18], xpos - 270, ypos + 400);
   image(imagesB[countB + 19], xpos - 285, ypos + 400);
   image(imagesB[countB + 20], xpos - 300, ypos + 400);
   image(imagesB[countB + 21], xpos - 315, ypos + 400);
   image(imagesB[countB + 22], xpos - 330, ypos + 400);
   image(imagesB[countB + 23], xpos - 345, ypos + 400);

which I wanted to simplify a little by using a variable increment. Or at least I was going to try.

Any help is appreciated.
Re: How do you make increments greater than 1
Reply #1 - Nov 25th, 2008, 11:29pm
 
You are adding, but not committing the resultant value to the variable.

Either:
x = x + 15;

or try the short hand

x += 15;
Page Index Toggle Pages: 1