I have created a "Mute" key in my game, so that when the player presses 'M' on the keyboard, the sound will go off, and when 'M' is pressed again it will go on. I have achieved this by detecting the keypress, toggling the flag of an object and then setting the master volume to 100 or 0 depending on the state of the flag.
To avoid using an object's flag, I initially tried to do it by changing a global variable (e.g. to 0 or 1) and reacting to the global variable, but I cannot achieve a toggling effect. I tried the 'obvious' conditions, e.g.
Upon pressing M & Mute = 0 : Main Volume = 100
Upon pressing M & Mute = 1 : Main Volume = 0
I then tried various limit conditions along with the above, but once the value has toggled one way, it won't toggle back. I am guessing that it is because the value is toggling, then the next test is occuring and immediately toggling back, but I am not sure.
Is there an obvious solution to my problem?
Incidentally, I thought I had asked this question recently, but I have searched my posts and can't find it, so I apologise if I have posted it and someone has already answered.