3 way switch

Hi There. I have been searching this forum, but didn't find an answer how to tackle the below:

I'd like to create a 3-way lever controller that controls the movement of a conveyor belt. Something like this:

L--S--R

Where L is left, S is stop, R is right. I want the player to control the motion of the belt by making a swipe movement over this controller. So if the knob is on S and the player swipes to the left the belt goes to the left and vice versa. Again when he swipes to the right the lever snaps into the stop position.

It seems a bit similar to the volume slider tutorial movie, but I want the knob of the lever to snap to the 3 different spots, and not be moving inbetween points.

Any help is most appriciated.

Kind regards,

Hidde.

Comments

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    Here is one way (among many):

    Make an integer (or index) attribute. Call it switchState (or whatever makes sense to you).
    Make two real attributes. Call call them swipeStartX and swipeEndX respectively.

    When touch is pressed
    -- Change Attribute: swipeStartX To: game.Mouse Position.X

    When touch is released
    -- Change Attribute: swipeEndX To: game.Mouse Position.X
    --When swipeEndX < game.swipeStartX -20
    ---- Change Attribute: self.switchState To: max(0, self.SwitchState -1)
    --When swipeEndX > game.swipeStartX +20
    ---- Change Attribute: self.switchState To: min(3, self.SwitchState +1)
    --Change Attribute: self.image To: self.switchState..".png"

    Note: Using this method, you would need to name the three graphics for the toggle switch to '1.png', '2.png', and '3.png'. 1.png would depict the toggle set to the left. 2.png would depict the toggle set to the middle position. And 3.png would depict the toggle set to the right position.

  • bacaljbacalj Member Posts: 2
    I have searched myself and continue to fail get an image to simply toggle back and forth on a click or touch.

    Have tried many variations, but I either get a looping on/off or stuck on one or the other.
  • SocksSocks London, UK.Member Posts: 12,822
    I have searched myself and continue to fail get an image to simply toggle back and forth on a click or touch.
    Here's what I usually use to toggle between two images (example attached):


    Have two images, one called '0' and one called '1' (no extension, just the number).
    In your actor have a rule which says:
    When actor is pressed > change self.image to 1-self.image.
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited October 2013
    Something like this?

    Edit: Oops.... @Socks beat me to it again!
  • bacaljbacalj Member Posts: 2
    @Socks - thanks a million. It totally works, and a cool number trick. (1-0 = 1 and 1-1 = 0)
  • SocksSocks London, UK.Member Posts: 12,822
    Something like this?

    Edit: Oops.... @Socks beat me to it again!
    : ) victory !
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited October 2013
    : ) victory !
    Not so fast there mister sock man. The OP was asking for a three-way toggle. And you only delivered a two-way switch.

    In order to obtain the grand prize -- you must complete the original challenge....

    Can you use your "no extension" GameSalad voodoo to create a three way toggle switch? (And thus save an innocent integer attribute from life stuck in toggle servitude!)
Sign In or Register to comment.