Hi all,
Got an odd one for you!!
I decided to branch out my slider brick puzzle game into a mini app, so I could learn by the experience of publishing an app as have never done so, and so now find myself coding audio into my app.
main.lua:
-- Sound FX channels reserved, so volume can be controlled. audio.reserveChannels(2) audio.reserveChannels(3) audio.reserveChannels(4) audio.setVolume( 0.5, { channel= 2 } ) -- button tap SFX audio.setVolume( 0.5, { channel= 3 } ) -- woosh touch SFX audio.setVolume( 0.5, { channel= 4 } ) -- success level completed SFX
options.lua
The code is long… so the bits relevant…
my forwarded declared variables:
local lblMusicVolume local lblSoundFX local options -- slider imagesheet options local sliderMusic -- slider itself local sliderSFX -- slider itself
Scene: Show Did:
again code adapted from your tutorials
local function sliderListenerSFX( event ) lblSoundFX.text = "Music Volume: " .. event.value .. "%" local setVolume = event.value/100 -- devide value by 100 to get a 0. number audio.setVolume( setVolume, { channel=2 } ) -- button tap audio.setVolume( setVolume, { channel=3 } ) -- woosh audio.setVolume( setVolume, { channel=4 } ) -- game success end sliderSFX = widget.newSlider( { sheet = graphics.newImageSheet( "images-ui/widget-slider.png", options ), leftFrame = 1, middleFrame = 2, rightFrame = 3, fillFrame = 4, frameWidth = 36, frameHeight = 64, handleFrame = 5, handleWidth = 64, handleHeight = 64, x = display.contentCenterX, y = lblSoundFX.y + 40, orientation = "horizontal", width = 300, value = audio.getVolume( { channel=2 } )\*100, -- moves button to the location that matchs volume % listener = sliderListenerSFX } ) groupUserInterface:insert(sliderSFX)
Everything above WORKS Fine. Volumes are adjusted nicely.
BUT once I’ve manipulated the volumes errors occur in my game play scenes during my brick creation code. These do not occur, if audio remains set by main.lua. Ive tested every which way I can think of and errors solely occur once I’ve adjust volume only.
As part of my bricks creation, I calculate their edges using contentBounds()
I put this code in a module, as many game play scenes will create many bricks, so I call this function from a module file that is required into all game play scene.
-- ---------------------------------------------- -- CALCULATE AN OBJECTS EDGES function mod.gfCalcEdges(objectIn) print("objectIn: " .. objectIn.myName) local objectOut = objectIn local bounds = objectOut.contentBounds -- assign edge parameters objectOut.leftEdge = bounds.xMin objectOut.topEdge = bounds.yMin objectOut.rightEdge = bounds.xMax objectOut.bottomEdge = bounds.yMax return objectOut end
But if the player is playing the game, decides the volume of SFX is too loud, quits the game, or even between completing levels, goes to options, tweaks the volume, the moment the next gameplay scene loads, and a brick is touched, this error is reported:
19:17:12.264 ERROR: Runtime error 19:17:12.264 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:386: attempt to index local 'bounds' (a nil value) 19:17:12.264 stack traceback: 19:17:12.264 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:386: in function 'gfCalcEdges' 19:17:12.264 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:91: in function 'calcCollision' 19:17:12.264 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:613: in function 'gfDetectCollision' 19:17:12.264 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\GP1.lua:524: in function '?' 19:17:12.264 ?: in function \<?:190\>
I’m completely stumped!!!
Help if you can.
Thanks
Angela