New to GS and need help with loops

I have the following, but it's not working consistently. I want a loop to run 4 times, but I don't get the same results every time. I suspect it might have something to do with the timer, but not sure. Is there something wrong with the logic?

Rule: Actor touch pressed
--Change Attribute: self.counter to 1
--Timer - every 0 seconds
----Rule: Attribute self.counter < 5
----Log Debugging Statement: self.counter
----Change Attribute: self.counter to self.counter + 1

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
  • dolphingamesdolphingames Member Posts: 3
    Thanks for you help. I had to look around how to use self mod timer , but got there in the end and it's now working. Many thanks.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    The problem probably isn't with the timer. It is with the logic of "When touch pressed". The inconsistent results you experience are likely due to letting up on the mouse -- and "pressed" is no longer true.

    You should get consistent results if you do it this way:

    Rule: Actor touch pressed
    -- Change Attribute: self.doLoop To: true

    Rule: When doLoop is true
    --Change Attribute: self.counter to 1
    --Timer - every 0 seconds
    ----Rule: Attribute self.counter < 5
    ------Log Debugging Statement: self.counter
    ------Change Attribute: self.counter to self.counter + 1
    ----Otherwise
    ------Change Attribute: doLoop To: false
  • dolphingamesdolphingames Member Posts: 3
    Thanks Thurman, that works great. I now understand why it wasn't working correctly and what was wrong with the logic.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    @dolphingames -- You are welcome! GameSalad is great once you get the hang of it.
Sign In or Register to comment.