persistent behaviors within rules
This is probably a simple fix, but I'm still learning GameSalad. How do you set up a rule where if the rule is met, the actor continues to do the persistent behavior even if the rule no longer applies?
Here is my problem. I want my actor to do the following: Start off not rotating. The first time someone touches it, it rotates clockwise at 90 until it is touched again. Once it has been touched to stop rotating clockwise, if it is touched again, it rotates counter-clockwise at 90 until it is touched again. Start the cycle over.
I tried setting up a boolean attribute named 'clockwise' and changing it to false the first time the actor is touched, but that just makes it stop rotating after one pixel because "actor - touch - released" and 'attribute - clockwise = true" aren't both true anymore.
Here is my problem. I want my actor to do the following: Start off not rotating. The first time someone touches it, it rotates clockwise at 90 until it is touched again. Once it has been touched to stop rotating clockwise, if it is touched again, it rotates counter-clockwise at 90 until it is touched again. Start the cycle over.
I tried setting up a boolean attribute named 'clockwise' and changing it to false the first time the actor is touched, but that just makes it stop rotating after one pixel because "actor - touch - released" and 'attribute - clockwise = true" aren't both true anymore.
Comments
test integer too
@mnoric
Hi, I'm not sure if, when you say "Start the cycle over", you mean back to stopped or not, the following assumes that it doesn't stop, but keeps flipping between clockwise and counter-clockwise, once started. If you want it to start rotating clock, then anti-clock, then stop, then clock, anti-clock, stop, etc let me know and I'll change the following rules for you.
So try this (two boolean attributes):
Rule: When touch is pressed
Change Attribute scene.StartA to true
Rule (nested in above rule) When scene.FlipA is false
Change Attribute scene.FlipA to true
Otherwise
Change Attribute scene.FlipA to false
------
Rule: When scene.StartA is true
Rule (nested in above) When scene.FlipA is true
Rotate Clockwise Speed 90
Otherwise
Rotate Counter-Clockwise Speed 90
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Using your code as an example, I have:
Rule: When touch is pressed
Rule (nested) When self.turning is true
Change Attribute self.turning to false
Otherwise
Change Attribute self.turning to true
Rule (nested in 'when touch is pressed' level): When self.clockwise is true
Change Attribute self.clockwise to false
Otherwise
Change Attribute self.clockwise to true
---
Rule: When Self.turning is true
Rule (nested): When self.clockwise is true
Rotate Clockwise Speed 90
Otherwise
Rotate Counter-Clockwise Speed 90
With that logic and with clockwise and turning both set to false at run time, the actor starts out not rotating. When you touch it, it goes back and forth between stopped and rotating clockwise. It never rotates counter-clockwise.
But OK, you want start, clock, counter-clock, stop, clock, counter-clock, stop, etc... so the Rules are different from the first version I gave, as I mentioned earlier.
Because you have 3 options now, it's best to have the states all in one attribute.
So make an integer attribute called Turning. You can do the following using the modulus (%) but the other way shown here is clearer as to what's going on:
Rule: When touch is pressed
Rule (nested in above) When self.Turning < 2
Change Attribute self.Turning to self.Turning+1
Otherwise
Change Attribute self.Turning to 0
Rule: When self.Turning = 1
Rotate Clockwise Speed 90
Rule: When self.Turning = 2
Rotate Counter-Clockwise Speed 90
Hope that sorts it for you now.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS