Cannot use two "touch pressed" events in one actor

I'm trying to create a mute button inside my game. I have an actor (the mute button) and one rule that says IF touch pressed AND devices.audio.soundVolume = 1 then change image to a mute icon and change the soundVolume to 0. I have another rule that says IF touch pressed AND devices.audio.soundVolume = 0 then change image to a sound on icon and change the soundVolume to 1.

Right now it doesn't work. But when I switched the touch pressed to two seperate random keyboard keys, it worked. But ofcourse it's much more annoying for the user to not just be able to left click and it switch. Does anyone know how to fix this?

Comments

  • NoobDevNoobDev Member, PRO Posts: 42

    If I’m reading this correctly then it sounds like your rules are looping. You can’t have rules that contradict each other inside of the same actor or else they will cancel each other out. There are many ways to fix this but the way I did this in my game is I created a table cell value integer but you can also use a game or actor attribute you’ll just have to remember to save that value so it stays constant even when the player quits and re enters the game.

    My table cell value is called “music toggle” and its default value is 1. In my actor I have 3 rules. One that says if touch is pressed change the value to (n+1)%2 “n” referencing your created attribute. This will change the value from 1 to 0 and from 0 to 1 every time you press the button. Then have two separate rules that say when this value is 1 change to a sound on icon and volume to 1 and the other rule says if this value is 0 change to mute icon and sound 0. Let me know if this works for you.

  • ForumNinjaForumNinja Key Master, Head Chef, Member, PRO Posts: 554

    There's a few ways to set something like what you're describing up. Check out this as one example: https://creator.gamesalad.com/#/game/u546547_blank_9ijl27mava05jlro1vbs5cm5p/prototype/id137943


    This project uses the mod function (which returns the value of the remainder of a division) to make an attribute repeat back and forth between 1 and 2 when the actor is pressed. Then you can set up a rule to run when that attribute has a value of 1 or 2 respectively.

  • ArmellineArmelline Member, PRO Posts: 5,364

    Mod is great for toggling between more than two numbers, but for toggling between 0 and 1 you can just use:


    Change attribute game.MyToggle to 1-game.MyToggle

    1-0 is 1, and 1-1 is 0.

Sign In or Register to comment.