Mute/Un-Mute Button
hanetrain
Member Posts: 5
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
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
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 . .
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
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
The Lost Oasis script worked perfect. Thanks!
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
Both methods will work for toggling between two values:
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
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
Real or Integer makes no difference to any of the methods suggested here.
Personally I just use: change X to 1-X
I favour booleans for such things. Even though they're functionally equivalent.
Contact me for custom work - Expert GS developer with 15 years of GS experience - Skype: armelline.support
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
Thank you guys
Make sure you use touch is pressed not released.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS