Repetitive Loop
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?
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
@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
If i want to perform task A first then go to task B then go back to task A. How to change the code?
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.
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
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.
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?
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?
@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.