Using (attribute+1)%3 for adding, How to write out when subtracting?
KillerPenguinStudios
Member Posts: 1,291
Hey guys,
In some of my rules I have:
When "something happens"
change attribute to (attribute+1)%3
But now I need to subtract. Have it basically say when attribute is less than 0 change it to 2. I currently have it the long way but wanted to know how it would be written like I have it above?
Thanks!
Comments
(attribute-1)%3
attribute < 0.
change attribute to 2.
What is the sequence you're wanting? Is it 3,2,1,3,2,1 or 2,1,0,2,1,0 or 2,1,2,1,2,1 for example?
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Just as I were to have (attribute+1)%3, it would be 0,1,2,0,1,2
I want the same thing but for subtracting so it would go 2,1,0,2,1,0
Basically it would go, if right is pressed change attribute to (attribute+1)%3
If left is pressed change attribute to attribute-1 but once 0 is reached it returns back to 2.
Would it be just as @Socks said, change attribute to (attribute-1)%3?
That is how I currently have it. Want it written out simpler as I have it for adding. Want it that way for other reasons to allow for other rules to work that would benefit from this!
Well, if you try (attribute-1)%3, I think you'll find that you're left with negative numbers. But it's easy enough to test...
I would do this:
When "something happens"
When attribute game.number = 0
Change Attribute game.number to 2
Otherwise
Change Attribute game.number to game.number - 1
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
(attribute-1)%3 will give him what he wants (0,2,1), if you wanted negative numbers you would use (attribute-1)%-3.
Do own a copy of GameSalad ?
Darnit, you're right @Socks. I trust Spotlight for my mod() adventures and it's never let me down... until now. (0-1)%3 results in -1 in Spotlight and 2 in GameSalad.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Don't use %
Use the mod function
mod(game.attribute-1,3)
Fortuna Infortuna Forti Una
There's been a big resurgence in the use of '%', it was triggered when @RThurman came out of the closet as a '%' user, everyone is doing it now, it's pretty cool.
I think he has been going to % Anonymous since then, not sure where he stands now.
Fortuna Infortuna Forti Una
That is essentially what I originally had but was causing big issues for what I was trying to accomplish. I was trying to get this to work in my level select scene. There are 10 levels total, 5 on top and 5 directly below. I wanted the player to be able to press the up or down to select a level directly above or below rather than having to scroll left or right and run through all the levels.
I was able to accomplish this with some long complex coding that didn't work 100% of the time and caused delays but With using (attribute+1)%10 and (attribute-1)%10 I am able to tell I can simply use (attribute+5)%10 and (attribute-5)%10 and it gives me exactly what I need and no issues! Thanks for the help @tatiang
AWESOME @Socks!!! Thanks a million!
HAHAHA, that was too funny! I def was not doubting you my friend!!!
Use my suggestion, don't be a rebel.
Fortuna Infortuna Forti Una
Hello... My name is RThurman and I am a recovering %-er.
Since joining % Anonymous I have only had one or two relapses.
I just want to report hat I am currently sober through the evening. Here is proof.
I actually changed all my % to mod because I thought @BlackCloakGS said it was better to use for some reason.
Yes SIR! Done and DONE!!!
HAHAHAHAHA!!! ROFL!!! BTW, thanks for the file! You all are great!!!
I just did the same thing!