Mute and Unmute in 1 Switch won´t work

Hey there … i can´t figure out why my mute button won´t work as i want him to.

When i cklick it first it mutes the whole sound. but when i want to unmute it i have to leave the scene and then i can unmute it. furthermore it doesn´t save the image for the muted situation. when it is muted and i leave and then go back to the scene … the image shows the unmuted one

here is my code for the switch

thank you!

local widget = require( "widget" ) local masterVolume = audio.getVolume() -- Handle press events for the checkbox local function onSwitchPress( event ) local switch = event.target if (masterVolume==0)then audio.setVolume( 1 ) print ("sound unmuted") else audio.setVolume( 0 ) print ("sound muted") end print( "Switch with ID '"..switch.id.."' is on: "..tostring(switch.isOn) ) end -- Image sheet options and declaration local options = { width = 120, height = 120, numFrames = 2, sheetContentWidth = 240, sheetContentHeight = 120 } local checkboxSheet = graphics.newImageSheet( "graphics/MUTEHD.png", options ) -- Create the widget local checkbox = widget.newSwitch { left = 465, top = 990, style = "checkbox", id = "Checkbox", width = 150, height = 150, onPress = onSwitchPress, sheet = checkboxSheet, frameOff = 1, frameOn = 2 } sceneGroup:insert(checkbox)

does no one got an idea?

You need to reset the variable masterVolume after you change it.  Right now it’s always whatever it was when you first required the module.

Rob

Thank you very much Rob! Next step is to find out how i can save the image from the switch when i changed the scene and come back :smiley:

does no one got an idea?

You need to reset the variable masterVolume after you change it.  Right now it’s always whatever it was when you first required the module.

Rob

Thank you very much Rob! Next step is to find out how i can save the image from the switch when i changed the scene and come back :smiley: