Using a specific set of numbers and rotating though them one by one.
GoatTeaBlend
Member, PRO Posts: 22
So I have a REAL attribute that represents 8 different colors, 1-8. I have 2 buttons that cycle though these colors (numbers) one at a time. Cycling up is working..1..2..3..4...ect, but going down takes the number to 0 and then is will not loop back to the number 8. Does anyone have an idea of resolving this issue. Thanks for your ideas.
Comments
Assuming the attribute name is "myNum," then to cycle up, the expression would be:
Change Attribute:[ myNum ] To:[ (myNum + 1)%9 ]
To cycle down, the expression would be:
Change Attribute:[ myNum ] To:[ (myNum - 1)%9 ]
I've always heard that the % sign would be depreciated and you should use the MOD function instead. Been hearing that for years though so...
but anyways, the same functions in the Mod format would look like:
Change Attribute:[ myNum ] To:[ mod(myNum + 1,9) ]
Change Attribute:[ myNum ] To:[ mod(myNum - 1,9) ]
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
@jonmulcahy -- Thats right!
I have a bad habit of using the "%" operator instead of using the mod() function. Thanks for turning the thread toward a more appropriate solution.
I only started using mod() a few weeks ago I was a die hard % supporter until i forced myself to switch.
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
I've tried to quit several times. Honest! But each time I just fall back into the same bad pattern.
I think its time for me to start attending some 7-step recovery program to get rid of this bad, bad habit.
Anyone know when the local ModAnon meeting starts?
+1> @RThurman said:
Both these will cycle around 0-8 rather than 1-8
mod( myNum ,8)+1 will work.
oops, you are right, I blindly followed @RThurman !
Send and Receive Data using your own Server Tutorial! | Vote for A Long Way Home on Steam Greenlight! | Ten Years Left
There are others, it might% not be obvious who they are%, but you% are not alone, many% of us suffer.
As a mod, I only use % about 20% of the time.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Let this be a lesson to all you young'uns out there.
See what bad habits will get you.
A totally derailed thread -- thats what it'l get you!
Now repeat after me:
Use mod() not %
Use mod() not %
Use mod() not %
...