How can I make an attribute go from 1 to 2, 2 to3, 3 to 4 and then 4 back to 1.

LordTarantorLordTarantor Member, PRO Posts: 890
edited November -1 in Working with GS (Mac)
I have an interger attribute called MovementDirection. Every time I press button A the attribute changes to MovementDirection +1. The movement on the Ship is like this: If movementDirection is 1 - Move Up. If it is 2 - Move Right. If 3 -Move Down and if 4 - Move Left.
Button B, when pressed, changes the attribute like this: MovementDirection to MovementDirection -1.
How can I keep the att in 1,2,3 and 4. If I press button A when the att is at 4 how to make it go to 1 instead of 5 and if it is at 1 and I press button B. How to make it go to 4 instead of 0.

Comments

  • olster1olster1 Member Posts: 396
    The only way I can think of is having more than 2 rules. But I'm sure there must be an efficient way of doing it with just 2 rules
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    (attribute+1)%4 will give you 0,1,2,3,0,1,2,3...
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Unless you absolutely need 1-4 this is the easiest and best way.

    When touch is pressed
    --Change attribute Game.Attribute to (game.attibute+1)%4

    The will cycle 0,1,2,3

    Now if you absolutely need 1-4 and cannot live with 0-3 you would do something similar but it will require an extra rule.

    When Touch is Pressed
    --Change attribute game.attribute to (game.attribute+1)%5

    And Then a rule
    When game.attribute = 0
    --Change Attribute game.attribute to 1

    ___________________________________________________________________________________
    TEMPLATES AND PROJECT HELP BY TENRDRMER. CLICK HERE!!!

    AppSolute Entertainment on Facebook
    AppSolute Entertainment on iTunes
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
  • quantumsheepquantumsheep Member Posts: 8,188
    jonmulcahy said:
    couldn't you just do

    change attribute to ((game.attibute+1)%4)+1?

    ARE YOU MAD????

    :D

    Dr. Sam Beckett never returned home...
    Twitter: https://twitter.com/Quantum_Sheep
    Web: https://quantumsheep.itch.io

  • jb15jb15 Member Posts: 602
    If I understand the effect you're going for (I think I do, but not positive) why don't you just say: Every time B is pressed rotate actor 90 degrees?
  • LordTarantorLordTarantor Member, PRO Posts: 890
    Hello guys. Thanks a lot for your answers. Scitunes and Tenrdrmer I am going to try your method.
    @jb15, I need this to be with attributes because there are a lot of other stuff that are linked to this movement.
  • jb15jb15 Member Posts: 602
    Oh. Well, you could do what I suggest, and have the numbers generated based on where the actor is facing (if actor.rotation = x), etc.

    Anway, I'd use tenrdrmer's way--it would use fewer rules--just throwing another option out there.
  • LordTarantorLordTarantor Member, PRO Posts: 890
    Scitunes and Tenrdrmer...
    Thanks a lot guys, it worked like a charm.
    I guess your approach works jb15 but like you said, fewer rules.

    Ps: @Tenrdrmer: as soon as this game gets approved I will send you a promo so you see what I did with the template I bought from you a couple of months ago ( Expanding Menus4).
    Thanks again.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    jonmulcahy said:
    couldn't you just do

    change attribute to ((game.attibute+1)%4)+1?

    Interesting. I guess that would work perfectly. I'll have to try that some time.
    LordTarantor said:
    Scitunes and Tenrdrmer...
    Thanks a lot guys, it worked like a charm.
    I guess your approach works jb15 but like you said, fewer rules.

    Ps: @Tenrdrmer: as soon as this game gets approved I will send you a promo so you see what I did with the template I bought from you a couple of months ago ( Expanding Menus4).
    Thanks again.

    Sounds great man. Can't Wait!!!
Sign In or Register to comment.