Repetitive Loop

KevinFlynnKevinFlynn Member Posts: 26
edited April 2013 in Working with GS (Mac)
I want to build a repetitive loop to perform 2 tasks and i want them to perform 3 counts each. For example:

If count = 0, then count+1 and perform A
If count = 3, then count-1 and perform B

How should i write this in gamesalad?

Comments

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    @KevinFlynn

    Hi Kevin, the following will work as you want, of course, except to say there's no loop involved; this is because the two statements you gave aren't linked, seeing as when count is zero it goes to 1; and when count is three it goes to 2. (They miss each other!)

    Rule: When Count = 0
    Change Attribute Count to Count+1
    ---perform A

    Rule: When Count = 3
    Change Attribute Count to Count-1
    ---perform B

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • KevinFlynnKevinFlynn Member Posts: 26
    edited April 2013
    @gyroscope

    If i want to perform task A first then go to task B then go back to task A. How to change the code?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    Hi, by changing the count to 0 & 1 accordingly (so the Count attribute could be a boolean now, as well as an integer, whichever you prefer).

    Rule: When Count = 0
    ---perform A
    ----timer only needed if the stuff in perform A takes a length of time
    Timer: After ? secs
    Change Attribute Count to 1

    Rule: When Count = 1
    ---perform B
    ----timer only needed if the stuff in perform B takes a length of time
    Timer: After ? secs
    Change Attribute Count to 0

    So that'll now loop continuously as you want.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • KevinFlynnKevinFlynn Member Posts: 26
    But this way they will not perform 3 counts each, got other solutions?
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    I'm almost certain I would have other solutions to help you, Kevin, if I had more info concerning when the count goes from 1 to 2, then 2 to 3, (and what you want to happen at those times) so as to trigger the second statement....

    As it stands at the moment, without more info from you, the only thing I can suggest is a guess to this & probably not what you're after (although the following will still loop):

    Rule: When Count = 0
    ---perform A
    ----timer only needed if the stuff in perform A takes a length of time
    Timer: After ? secs
    Change Attribute Count to 1

    Rule: When Count = 1
    ---perform B
    ----timer only needed if the stuff in perform B takes a length of time
    Timer: After ? secs
    Change Attribute Count to 2

    Rule: When Count = 2
    ---perform C
    ----timer only needed if the stuff in perform B takes a length of time
    Timer: After ? secs
    Change Attribute Count to 3

    Rule: When Count = 3
    ---perform D
    ----timer only needed if the stuff in perform B takes a length of time
    Timer: After ? secs
    Change Attribute Count to 0

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited April 2013
    Just look at the logic he presented. You can just add to it like @gyroscope just did. A little advice, don't just look for a complete answer but learn what he is showing you. Knowing how this stuff works will help you learn to design your own code and help you in the future.

    Like say a grow/shrink loop. If you have an actor 26 x 50 and you want to shrink it to 10 x 28 and then grow back and shrink again you would write it like this.

    Rule

    When self.size.width = 26 (we only need to monitor one dimension for the trigger)

    Interpolate: self.size width to 10 duration 1 second.
    Interpolate: self.size height to 28 duration 1 second.

    Rule

    When self.size.width = 10

    Interpolate: self.size.width to 26 duration 1 second.
    Interpolate: self.size.height to 50 duration 1 second.

    This is how you do a loop in logic. You start with one condition and one the condition is met the second kicks in and so on.
  • KevinFlynnKevinFlynn Member Posts: 26
    edited April 2013
    @gyroscope

    Yes, using timers can solve this as the count is 1 count/sec. I just want to perform task A that lasts for 3 counts then switch to task B that also lasts for 3 counts. The action starts when the user opens the app. Is it possible to do a repetitive for loop automatically without writing all the rules? For example, if i have 100 counts, do i need to have 100 rules without timers?
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    If you need to count every step is associated with an action then yes. If not then I would use a timer instead of a count for the loop or some other traceable variable related to the action.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited April 2013

    Cheers to Dave of @FryingBaconStudios for the mention and his insightful comment.

    @KevinFlynn

    So if I'm understanding you correctly now Kevin, you're not actually updating an attribute called count, you were using the word "count" in the pseudocode sense, to mean a second?

    If that's right, then the following will do what you're after: (I've replaced the name of the boolean called count with one called GoLoop)

    Rule: When GoLoop is false
    ---perform A stuff
    Timer: After 3 seconds
    Change Attribute GoLoop to true

    Rule: When GoLoop is true
    ---perform B stuff
    Timer: After 1 seconds --- or After perform B stuff has finished
    Change Attribute GoLoop to false

    Is that what you're after?

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • KevinFlynnKevinFlynn Member Posts: 26
    edited April 2013
    @gyroscope
    @FryingBaconStudios

    In this case, count is an attribute used as boolean. Got it to work after using timer to slow down the count. Thank you both.

Sign In or Register to comment.