Hi all,
I have created a settings page which contains a switch widget (On and Off switch) and I have created a function like so:
local function onSwitchPress( event ) local switch = event.target local response = switch.id.." is on: "..tostring( switch.isOn ) print( response ) if (switch.isOn == true) then print("It's on") gameFile.kickSound = audio.loadSound("sounds/kick.mp3") gameFile.defencePop = audio.loadSound("sounds/pop.mp3") gameFile.winSound = audio.loadSound("sounds/win.mp3") gameFile.loseSound = audio.loadSound("sounds/lose.mp3") elseif (switch.isOn == false) then print("It's off") gameFile.kickSound = nil gameFile.defencePop = nil gameFile.winSound = nil gameFile.loseSound = nil end end
kickSound, defencePop, winSound and loseSound are in another file called ‘game’ and are global (and set as nil). I have also called the ‘require’ method at the start of this file.
When I run the game, there is no music. When I restart the program, go to the settings page, even if the switch is On or Off, when I return to the game, music still plays.
How do I solve this?