I need help regarding my widget switch button. I’ve created 2 switch button which is for sound switch and music switch but the problem is every time i switch off and switch on the music switch the music(mp3 sound) is being unresponsive means its speed is fastforwarding every time i switch music on/off. Next problem is Everytime i switch off sound switch it also switch off the music(mp3 sound).
Heres my code:
–utils.lua
local sounds = {} sounds["select"] = audio.loadSound("sounds/select.mp3") sounds["score"] = audio.loadSound("sounds/score.mp3") sounds["incorrect"] = audio.loadSound("sounds/gameover.mp3") sounds["clap"] = audio.loadSound("sounds/clapping.mp3") sounds["music"] = audio.loadSound("sounds/gameMusic.mp3") M.playSound = function(name) if sounds[name] ~= nil then audio.play(sounds[name]) end end
–Settings.lua
soundSwitchPressed = function(event) local switch = event.target utils.playSound("select") if switch.id == "sound" then if switch.isOn == true then audio.setVolume(0) else audio.setVolume(1) end end end musicSwitchPressed = function(event) local switch = event.target utils.playSound("music") if switch.id == "music" then if switch.isOn == true then audio.setVolume(0) else audio.setVolume(1) end end end local sound\_switch = widget.newSwitch { left = \_W-70, top = navBar.y + navBar.height/2 + 44, style = "onOff", id = "sound", x = 800, y = 960, onPress = soundSwitchPressed } sound\_switch.xScale, sound\_switch.yScale = 3, 3 uiGroup:insert(sound\_switch) local music\_switch = widget.newSwitch { left = \_W-70, top = navBar.y + navBar.height/2 + 44, style = "onOff", id = "music", x = 800, y = 1200, onPress = musicSwitchPressed } if audio.getVolume() == 0 then sound\_switch:setState({isOn=false, isAnimated=false}) music\_switch:setState({isOn=false, isAnimated=false}) else sound\_switch:setState({isOn=true, isAnimated=false}) music\_switch:setState({isOn=true, isAnimated=false}) end end