GameSalad

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Mute/Un-Mute Button

I'm having trouble getting a button to un-mute after muting.
I have an actor that when:
Touch is pressed
and Game.audio.sound volume is > 0
Do: Change attribute game.audio.sound volume to 0
and Change image (to mute image)

Next rule on same actor

Touch is pressed
and Game.audio.sound volume is = 0
Do: Change attribute game.audio.sound volume to 1
and Change image (to unmute image)

If i turn the second rule off, then the first one works fine to mute. However I want to be able to click the same button and have it mute/unmute with corresponding image change. Anyone know how to make these rules work together? Or alternate ways to solve this of course.

Comments

  • SocksSocks London, UK.Posts: 12,822Member
    edited November 2015

    First, change your image names to '0' and '1'

    When touch is pressed:
    --Change sound volume to 1-sound volume
    --Change image to 1-image

  • SocksSocks London, UK.Posts: 12,822Member
    edited November 2015

    @hanetrain said:
    I'm having trouble getting a button to un-mute after muting.
    I have an actor that when:
    Touch is pressed
    and Game.audio.sound volume is > 0
    Do: Change attribute game.audio.sound volume to 0
    and Change image (to mute image)

    Next rule on same actor

    Touch is pressed
    and Game.audio.sound volume is = 0
    Do: Change attribute game.audio.sound volume to 1
    and Change image (to unmute image)

    If i turn the second rule off, then the first one works fine to mute. However I want to be able to click the same button and have it mute/unmute with corresponding image change. Anyone know how to make these rules work together? Or alternate ways to solve this of course.

    The problem here is that you are asking the actor to do two opposing things at the same time . . . . .

    The first rule is saying, when touched change sound to 0 . .
    And as the sound changes to 0 - and your finger is on the button - this means the second rule's conditions are met so it triggers too . .

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member

    Use the mod function.

    Make a self attribute called ON/OFF

    Rule

    When touch is pressed

    Change att self.on/off to mod((self.on/off+1),2)

    This will toggle self.on/off between 1 and 0 each time you press. I have a video on it.

    Rule

    When attribute self.on/off = 1

    Change attribute game.sound to 0
    Change image to off image

    Otherwise

    Change attribute game.sound to 1
    Change image to sound on image

  • hanetrainhanetrain Posts: 5Member

    The Lost Oasis script worked perfect. Thanks!

  • KozaxKozax London, UKPosts: 9Member

    Thank you @Lost_Oasis_Games.

    I tried your method but it only changes once(from 0 to 1), it doesn't toggle between the two values.
    Do you know if there is something changed with the software since your post?
    Also, I assumed the attribute you created is an integer.
    Thanks

  • tatiangtatiang Posts: 11,845Member, Sous Chef, PRO, Senior Sous-Chef

    Both methods will work for toggling between two values:

    1. Change Attribute game.value to mod(game.value+1),2
    2. Change Attribute game.value to 1-game.value

    Make sure game.value is an integer attribute with a starting value of 0 or 1.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • SocksSocks London, UK.Posts: 12,822Member
    edited February 2016

    @tatiang said:
    Both methods will work for toggling between two values:

    1. Change Attribute game.value to mod(game.value+1),2
    2. Change Attribute game.value to 1-game.value

    Make sure game.value is an integer attribute with a starting value of 0 or 1.

    You've suffered bracket displacement (painful if left untreated).

    mod(game.value+1),2 ....... should be ....... mod(game.value+1,2)

    Also, it doesn't really matter whether the attribute is real or integer in this situation.

    /Pedant :p

  • SocksSocks London, UK.Posts: 12,822Member

    @Kozax said:
    Thank you @Lost_Oasis_Games.

    I tried your method but it only changes once(from 0 to 1), it doesn't toggle between the two values.
    Do you know if there is something changed with the software since your post?
    Also, I assumed the attribute you created is an integer.
    Thanks

    Real or Integer makes no difference to any of the methods suggested here.

    Personally I just use: change X to 1-X

  • ArmellineArmelline Posts: 4,775Member, PRO

    I favour booleans for such things. Even though they're functionally equivalent.

  • tatiangtatiang Posts: 11,845Member, Sous Chef, PRO, Senior Sous-Chef

    Lol! I did suffer bracket displacement. That tends to happen in old age. I've seen my parenthepractor and he assures me the situation has been resolved.

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • KozaxKozax London, UKPosts: 9Member

    Thank you guys :)

  • The_Gamesalad_GuruThe_Gamesalad_Guru Posts: 9,913Member

    Make sure you use touch is pressed not released.

Sign In or Register to comment.