Oh right! Thanks for the reply
but I met with some problems when adding the code
I have a settingmenu.lua where the checkbox is at and a game scene.lua where the device will vibrate will my health reduce
--Handles the press event for the checkbox local function onSwitchPress( event ) -- body local switch = event.target print("Switch with ID '"..switch.id.."' is on:" ..tostring(switch.isOn)) --Enable vibration when the check box for Vibrates is checked. if (switch.isOn) then -- If the checkbox is checked, then run this code. print( "Switch is on, Vibrate the device" ) system.vibrate() -- Vibrate the device end end
For this it works but it does not works in the gamescene
Game Scene.lua:
elseif event.other.IsPit then if player.invul == false then local disableInvul = function() player.invul = false pauseBtn.alpha = 1 end decreaseHealth(1) -- Health -1 if (switch.isOn) then -- Check if the checkbox is on print( "Vibrate the device" ) system.vibrate() -- Vibrate the device end
It gives an error like this “attempt to call “switch” a nil value” (It does not run the if statement, it gives an error when entering the statement)
Am I missing out something??
Sorry, just started Corona 2 weeks ago.