Moving Actor Between 3 Points with 2 Buttons

Hi there, I'm having a bit of trouble with getting a particular function to work when I try to move an actor between three points on the scene. I'm using 3 actors, one being the player, and two for moving the actor. On the player I have a rule to constrain its X position to a Game integer called "playerPosition" and have it set to 180 by default.

On the other actors I have two rules each: one to center the player and one to move it either right or left (respective to the button being pushed). What I'd like to happen is that if the player is on the rightmost side of the scene (300) and you push the left button, it moves to the center (180), and then if you push the left button again (with the player being in the center) it will move to the leftmost side of the screen (80). On the transverse, if the player is on the leftmost side of the screen and you push the right button, it should first move to the center, with a second push moving it to the rightmost.

The centering rule for the right button reads: when all conditions are met: touch is pressed and playerPosition=80, do: change attribute playerPosition to 180. (The centering rule for the left just changes the playerPosition condition to 300.)

The other movement rules read: when all conditions are met: touch is pressed and playerPosition=180, do: change attribute playerPosition to 80(for left) or 300(for right).

It seems what's happening is that it's performing both rules in rapid succession, when I want there to be a pause in between each rule being run, so that the player centers when either the left or right button are pushed, and requires a second push to move it leftmost or rightmost. Can anyone help with this? Thanks!

Answers

  • thedpozthedpoz Member Posts: 2

    Solved with the power of Timer. I added a boolean Game attribute called playerMoveable set to true by default, then a condition on all rules to require playerMoveable be true. On the centering rules DO I added to change the attribute to false, then a Timer run to completion that AFTER 0.1 seconds to change the attribute back to true.

    All is well now.

Sign In or Register to comment.