Actor to alternate between two positions

lolchopslolchops Member, PRO Posts: 9
edited December 2014 in Working with GS (Mac)

I really didn't want to post a question but I've exhausted Youtube and the forums and my brain isn't quite working like a programmer yet.

I want to have an actor move to 2 alternating positions when a different single button actor is pressed (like a door that slides left when button pressed and then slides right when button pressed again) There's one of these on each half of the screen L & R.

I figured out how to do this with touching the door actor itself but I want an invisible half-screen actor on each side to control the door on each side. Touch on the left side or the right side of the screen. Similar to control of "2 Cars" game by Ketchapp, if you've seen that.

Seems simple enough but I can't figure it out and tried changing attributes and timers checking for the attributes and a million things. Brain hrts. Hlp.

Best Answers

  • gyroscopegyroscope I am here.Posts: 6,598
    edited December 2014 Accepted Answer

    Hi, I deleted that boolean, because I wrote it off the top of my head, only realising it wasn't needed afterwards but missed one to delete - so to confirm, no worries, here it is again without that unneeded attribute: (I've also rectified another mistake or two I made - so make the attribute Door1Switch a boolean)

    Rule: When touch is pressed
    --Nested in above rule-- Rule: When Door1Switch = 0
    Change Door1Switch to 1
    Otherwise
    Change Door1Switch to 0
    

    Now unlock the left door actor's rules and put:

    Rule: When Door1Switch = 1
    Interpolate self.Position.X to ?? -- a position to the left of the starting x pos.
    Interpolate rightdooractor.Position.X to ?? -- a position to the right of the starting x pos.
    Otherwise
     Interpolate self.Position.X to ?? -- a position to the right, back to starting x pos.
        Interpolate rightdooractor.Position.X to ?? -- a position to the left, back to starting x pos.
    

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • jorkosjorkos Posts: 353
    Accepted Answer

    the best way to do the press is when pressed: change attribute (attribute +1%2)

    then just have the rules for different values. note that this takes it from 0 to 1 and then back to 0 so make your rules accordingly. if you start the game with the value at 2 (so it doesn't trigger the rule) when you click it it will go to 1 and then back to 0.....fyi......just depends how you want to do this. overall it's important to learn how to do these cycles, for example if you want to cycle through 4 options you just do: (attribute +1%4).... very useful in a lot of situations

Answers

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2014

    Hi @lolchops Try something like the following:

    Make an integer attribute, let's call it Door1Switch

    Put your two actors either side of your door, making their Alpha to 0.

    I've assumed that by pressing the invisible buttons when the doors are open, they'll close again...

    Put in both of these invisible actors' Rules:

    Rule: When touch is pressed
    --Nested in above rule-- Rule: When Door1Switch = 0
    Change Door1Switch to 1
    Change attribute Door1Switch to 2
    Otherwise
    Change Door1Switch to 2
    Change attribute Door1Switch to 1
    

    Now in the left door actor's rules, put:

    Rule: When DoorGo is true
    --nested in above rule-- Rule: When Door1Switch = 1
    Interpolate self.Position.X to ?? -- a position to the left of the starting x pos.
    Otherwise
    Interpolate self.Position.X to ?? -- a position to the right of the starting x pos.
    

    The above is untested but should work OK.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • lolchopslolchops Member, PRO Posts: 9
    edited December 2014

    Thanks @gyroscope‌ I'll try that when I get home from work. What function does the "DoorGo" attribute you mentioned have though?

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    edited December 2014

    @jorkos said:
    the best way to do the press is when pressed: change attribute (attribute +1%2)

    Don't know about that being the best way - tho' more elegant programming, I guess - both methods produce the same results in this case.

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Sign In or Register to comment.