Toggling

KC_GamesKC_Games Member, PRO Posts: 86

I want a toggle that also checks if something is selected before toggling. There is an integer "selected" that is 0 that I want to toggle to 1 if 0, and to 0 if 1 (both on touched). This isn't working. Any help please?

Comments

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

    The rules get triggered constantly because when you click/tap and self.selected is 0, it causes self.selected to be 1 but... you're still clicking/tapping so it then causes self.selected to be 0 but... you're still... okay, you get the idea.

    Try this:

    When touch is pressed
    Change attribute self.selected to 1-self.selected

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • jorkosjorkos Member, PRO Posts: 353

    this is not how to do this. you want one rule:

    if touched, then change attribute: (attribute +1)%2

    that toggles between 0 and 1

  • KC_GamesKC_Games Member, PRO Posts: 86

    Thanks for the replies. Ok, so both suggestions work great, but not for what I am trying to do in my game. What I want to do is increase a variable integer +1 if the box is touched (and not currently in a touched state) and reduce the integer if touched but in a touched state. So in the example below, if you click all three boxes, the white box number should increase from 0 to 3, but if you touch a box that had already been touched, it will reduce to 2. If you touch the same exact box now in an untouched state, it will go back to 3. I hope that makes sense. I attached the project.

  • LovejoyLovejoy Member Posts: 2,078

    @DreamsComeTrue said:
    Thanks for the replies. Ok, so both suggestions work great, but not for what I am trying to do in my game. What I want to do is increase a variable integer +1 if the box is touched (and not currently in a touched state) and reduce the integer if touched but in a touched state. So in the example below, if you click all three boxes, the white box number should increase from 0 to 3, but if you touch a box that had already been touched, it will reduce to 2. If you touch the same exact box now in an untouched state, it will go back to 3. I hope that makes sense. I attached the project.

    Like this?

    Fortuna Infortuna Forti Una

  • KC_GamesKC_Games Member, PRO Posts: 86

    @Lovejoy , you are awesome. Thanks that looks so easy looking at it now. Thank you!

Sign In or Register to comment.