menu.lua :Attemp to index global 'musicOn' (a nil value)

i already created a local variable for musicOn. 

menu.lua “11” :Attemp to index global ‘musicOn’ (a nil value)

local function onMusicButtonTouch( event ) if "began" == event.phase then print("music button is pressed.") if (musicEnabled) then musicOff.alpha = 1 musicOn.alpha = 0 audio.setVolume( 0, { channel=musicAudioChannel } ) musicEnabled = false print("Music disabled") else musicOn.alpha = 1 musicOff.alpha = 0 audio.setVolume( 0, { channel=musicAudioChannel } ) musicEnabled = true print("Music enable") end end return true end function scene:create( event ) local sceneGroup = self.view local background = display.newImage("images/background2.jpeg", display.contentHeight, display.contentWidth) background:addEventListener( "touch", stopTouches ) background:addEventListener( "tap", stopTouches ) background.anchorX = 0 background.anchorY = 0 background.x, background.y = 0, 0 local mainMenu = display.newGroup() local musicOff = display.newImageRect(mainMenu,"images/Buttons/Music1.png", 300, 300 ) musicOff.x = 690 musicOff.y = 1750 local musicOn = display.newImageRect(mainMenu, "images/Buttons/Music.png", 300, 300 ) musicOn.x = 690 musicOn.y = 1750 musicOff:addEventListener("touch", onMusicButtonTouch) musicOn:addEventListener("touch", onMusicButtonTouch) mainMenu.musicOff = musicOff mainMenu.musicOn = musicOn end

esco,

same situation here as the problem in your other post,  ‘scope’.   Declare the button object ‘musicOn’ as local near the top of your module, not inside the function ‘scene:create’

define it in scene:create is okay, but it must be declared outside of that function. So just remove ‘local’ from line 35  …

near the top of the module declare it   ->   local musicOn

Bob

My goodness it worked im learning a lot from you Bob Thank you !! …

esco,

same situation here as the problem in your other post,  ‘scope’.   Declare the button object ‘musicOn’ as local near the top of your module, not inside the function ‘scene:create’

define it in scene:create is okay, but it must be declared outside of that function. So just remove ‘local’ from line 35  …

near the top of the module declare it   ->   local musicOn

Bob

My goodness it worked im learning a lot from you Bob Thank you !! …