How do I make a button that turns on when pressed then off when pressed again?
DinoBit
Member Posts: 23
I am pretty new to this kind of stuff. I know how to make a normal button, but how do I make a button that turns on when pressed then off when pressed again?
Comments
when touch is pressed
do
change image to ( whatever is your turned on image)
else
change image to (the one that was already displaying when it was not pressed)
With a boolean, there can be a problem with the rule running in a loop (if touch is pressed and true, change to false; if touch is pressed and false, change to true; BUT uh oh, when it changes to false and I'm still touching the actor, it then changes immediately to true... argh!)
When touch is pressed
Change attribute game.anInteger to 1-game.anInteger
So if game.anInteger is 0, it will change to 1. If game.anInteger is 1, it will change to 0.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Thank you!
For the record, for new users, the loop method is watertight providing it's done properly using the Otherwise section (although not as elegant as your solution, @tatiang ! )
Rule:When touch is pressed
Rule ---nested--:When BoolLoop is false
Change Attribute BoolLoop to true
--do your thing
Otherwise
Change Attribute BoolLoop to false
--do your other thing
@TomCoffee Any type of loop is only "fiddled" with timers if you want a pause before the next loop iteration; or to to give a time limit to the loop, for instance – both valid uses of timers.
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
And I can't take credit for the subtraction method. I always see @Socks post it. B-)
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User