Volume Button Toggle

Okay, so I have a single button that will toggle the music on and off, with there being two images for each. But for some reason, its not working. Anyone have a small demo available that I can look at? Thanks!

Comments

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    edited August 2013
    Have you got two rules underneath each other i.e.

    When On and Pressed/Released
    Turn Off

    When Off and Pressed/Released
    Turn On

    That would definitely give you problems if so.

    Not got a demo but in my last game I've got a simple rule that was checking what the current image was i.e.

    When Image = On And Pressed/Released
    Change Image To Off
    Stop Music
    Otherwise
    Change Image To On
    Play Music

    I didn't have music in mine but my pause and play scene button was set up similar to the above.
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    While @KevinCross is correct, there's a better way to accomplish this.

    Create one game attribute (integer type) and name it "MusicON/OFF".
    Inside your button, add a rule with the condition TOUCH IS PRESSED. Inside the rule, add a change attribute behavior that says:

    Change Attribute game.MusicOn/OFF to (game.MusicON/OFF+1)%2

    Every time this actor is touched, it will add to the game attribute if it equals 0. If it equals 1, it will change the attribute to 0. You can guess the next steps:

    Rule:
    When attribute game.MusicON/OFF = 0,
    Change attribute Device.Audio.Music to 1.
    Change image: Your choosing

    Rule:
    When attribute game.MusicON/OFF = 1,
    Change attribute Device.Audio.Music to 0.
    Change image: Your choosing

    Now you can add your play music behavior and don't have to worry about pausing the music -- the logic above will just mute the music.

    Hope this helps

  • KevinCrossKevinCross London, UKMember Posts: 1,894
    Thanks @Braydon_SFX, I remember seeing this toggle code using Mod recently in a post but I couldn't find it when I looked a few days ago. Bookmarking it for future reference
Sign In or Register to comment.