press actor once moves it one way press it again moves the other way
myu699
Member Posts: 96
Hey guys! I am working on a new game but have run into a problem. What I want to do is have a button that when pressed moves an actor to the side, but when that same button is pressed again it goes the opposite way. Thanks!
Comments
Create an integer attribute called game.direction and set its value to 0. Have a rule that says If Touch is Pressed, change attribute game.direction to 1-game.direction. This will toggle the value back and forth between 0 and 1 each time the actor is clicked. Then have a rule for If attribute game.direction=0... and for If attribute game.direction=1.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Ok thanks will make sure to try it out!
@tatiang just to be clear. Does it say 1 minus game.direction?
Yes, one minus game.direction. This is an efficient way to switch between two values, namely 0 and 1.
If the attribute is 0, then 1-0 = 1.
If the attribute is 1, then 1-1 = 0.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
@myy699 I would use a self.attribute on that actor instead of a game.attribute if that's the only actor that will be changing direction.
Good point, @AJaymz.
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
thanks
Another way is to make an Index Attribute.
In the Rule...
When touch is pressed,
Change attribute to (your.index+1)%2
So you have by every press the change between 0-1
dapion.de
[https://twitter.com/dapionde?]