Limit numbers to a certain range

CircleTimeCircleTime Member Posts: 84
edited November -1 in Working with GS (Mac)
If I had a range of numbers that I needed to stay within, say 0-480... then I started adding numbers all the way up to 480... but when I hit this upper limit of 480... the number looped back through 0... then continued adding up.

How?

I've seen a sample of this code before, but I can't find it after much searching... it used a symbol such as % or & to do this trick.

Advance thanks,
CircleTime

Comments

  • CircleTimeCircleTime Member Posts: 84
    It is actually in an expression with a little math.
    I'm adding a few numbers, but if the total exceeds 480, I want it to loop to 0 and continue up.
    For example, if all the added numbers equal 500, I'd like it to return 20.
    Thoughts?
  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    change attirubte to (attrubte+1)%2

    that will make it so when that happens it adds 1, then when the numbers 1 and it adds it goes back to 0. So it toggles between 0 and 1.

    So for what you want:

    change attirubte to (attirubte+1)%481

    that expression will add one, then when it gets to 480 and changes itll reset to 0.

    Its called modulus, its very usefull for on/off buttons, toggles ect.
  • CircleTimeCircleTime Member Posts: 84
    @john
    PERFECT!!! Thank you.
Sign In or Register to comment.