Save Mute Button Setting

In my game, I have two scenes; the menu scene and the game scene. In my game scene, I have a mute button. It works fine during the game, but if I set it to mute, and then I go back to the menu, and then I go back to the game, it is not set to mute anymore. How do I get my game to save the setting on the mute button? Here is the code for my mute button:

local mutebuttonclicked = display.newImage("MuteButtonClicked.png")  
localGroup:insert(mutebuttonclicked)  
mutebuttonclicked.x = 1000  
local mutebutton = display.newImage("MuteButton.png")  
localGroup:insert(mutebutton)  
mutebutton.x = display.contentWidth-25  
  
soundOn = true  
function unmuting(event)  
if event.phase == "began" then  
soundOn = true  
--IF SOUNDON = TRUE, THEN THERE WILL BE SOUND IN THE GAME  
--IF SOUNDON = FALSE, THEN THERE WILL NOT BE SOUND IN THE GAME  
mutebuttonclicked.x = 1000  
mutebutton.x = display.contentWidth - 25  
end  
  
end  
mutebuttonclicked:addEventListener("touch",unmuting)  
  
function muting(event)  
if event.phase == "began" then  
soundOn = false  
--IF SOUNDON = TRUE, THEN THERE WILL BE SOUND IN THE GAME  
--IF SOUNDON = FALSE, THEN THERE WILL NOT BE SOUND IN THE GAME  
mutebutton.x = 1000  
mutebuttonclicked.x = display.contentWidth - 25  
end  
end  
mutebutton:addEventListener("touch",muting)  
  

Thanks! [import]uid: 38001 topic_id: 11393 reply_id: 311393[/import]

Try line 10: if soundOn ~= false then soundOn=true

what is happening i suppose that soundOn is initialised to true always… i am assuming soundOn is visible across your scenes.

[import]uid: 55009 topic_id: 11393 reply_id: 41302[/import]

I tried that and it didn’t work. And no soundOn is not visible across my scenes. How do I do that?
[import]uid: 38001 topic_id: 11393 reply_id: 41314[/import]

Hey,

Add _G. in front of it to make it visible across all scenes when using director. So “_G.soundOn”, without the quotes, of course.

Is there a reason that you need to say that soundOn = true where you do? Every time this scene is loaded it will be set to true if you do it in this way.

Peach [import]uid: 52491 topic_id: 11393 reply_id: 41350[/import]