Using (attribute+1)%3 for adding, How to write out when subtracting?

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

  • SocksSocks London, UK.Member Posts: 12,822

    (attribute-1)%3

  • RabidParrotRabidParrot Formally RabidParrot. Member Posts: 956
    edited March 2015

    attribute < 0.
    change attribute to 2.

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    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

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @tatiang said:
    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?

    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?

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @RabidParrot said:
    attribute < 0.
    change attribute to 2.

    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!

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    edited March 2015

    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

  • SocksSocks London, UK.Member Posts: 12,822
    edited March 2015

    @tatiang said:
    Well, if you try (attribute-1)%3, I think you'll find that you're left with negative numbers.

    (attribute-1)%3 will give him what he wants (0,2,1), if you wanted negative numbers you would use (attribute-1)%-3.

  • SocksSocks London, UK.Member Posts: 12,822

    @KillerPenguinStudios said:
    Would it be just as Socks said, change attribute to (attribute-1)%3?

    Do own a copy of GameSalad ?

    ;)

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    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

  • LovejoyLovejoy Member Posts: 2,078

    Don't use %

    Use the mod function

    mod(game.attribute-1,3)

    Fortuna Infortuna Forti Una

  • SocksSocks London, UK.Member Posts: 12,822

    @Lovejoy said:
    Don't use %

    Use the mod function

    mod(game.attribute-1,3)

    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.

  • LovejoyLovejoy Member Posts: 2,078

    @Socks said:
    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

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @tatiang said:
    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

    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

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @Socks said:
    (attribute-1)%3 will give him what he wants (0,2,1), if you wanted negative numbers you would use (attribute-1)%-3.

    AWESOME @Socks!!! Thanks a million!

    @Socks said:
    Do own a copy of GameSalad ?
    ;)

    HAHAHA, that was too funny! I def was not doubting you my friend!!! :p

  • LovejoyLovejoy Member Posts: 2,078

    Use my suggestion, don't be a rebel.

    Fortuna Infortuna Forti Una

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    @Socks said:
    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.

    @Lovejoy said:
    I think he has been going to % Anonymous since then, not sure where he stands now.

    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.

  • BBEnkBBEnk Member Posts: 1,764

    I actually changed all my % to mod because I thought @BlackCloakGS said it was better to use for some reason.

  • KillerPenguinStudiosKillerPenguinStudios Member Posts: 1,291

    @Lovejoy said:
    Use my suggestion, don't be a rebel.

    Yes SIR! Done and DONE!!!

    @RThurman said:
    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.

    HAHAHAHAHA!!! ROFL!!! BTW, thanks for the file! You all are great!!!

    @BBEnk said:
    I actually changed all my % to mod because I thought BlackCloakGS said it was better to use for some reason.

    I just did the same thing!

Sign In or Register to comment.