Adjusting audio.setVolume() in options.lua , cause errors to contentBounds() on objects with SFXs in game.lua files?

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

 

I’ve narrowed it down to the object being passed to the function that has the problem.
How do I inspect down further layers of the object?

EG

My function now is:

 

-- ---------------------------------------------- -- CALCULATE AN OBJECTS EDGES function mod.gfCalcEdges(objectIn) print("gfCalcEdges objectIn: " .. objectIn.myName) print("TYPE: " .. type( objectIn ) ) print("line.\_properties: " .. json.prettify( objectIn.\_properties ) ) local objectOut = objectIn local bounds = objectIn.contentBounds print( "xMin: ".. bounds.xMin ) -- xMin: 75 print( "yMin: ".. bounds.yMin ) -- yMin: 75 print( "xMax: ".. bounds.xMax ) -- xMax: 125 print( "yMax: ".. bounds.yMax ) -- yMax: 125 -- assign edge parameters objectOut.leftEdge = bounds.xMin objectOut.topEdge = bounds.yMin objectOut.rightEdge = bounds.xMax objectOut.bottomEdge = bounds.yMax return objectOut end

Line 386, prints a long list of properties for the object when the function is called and the SOUND has not been adjusted.

But the exact same code, after sound adjustment causes the error.

 

gfCalcEdges objectIn: Brick Yellow 20:51:53.090 TYPE: table (LINE 385 above) 20:51:53.090 ERROR: Runtime error 20:51:53.090 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:386: json.prettify called with nil string 20:51:53.090 stack traceback: 20:51:53.090 [C]: in function 'error' 20:51:53.090 ?: in function 'prettify' 20:51:53.090 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:386: in function 'gfCalcEdges' 20:51:53.090 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:92: in function 'calcCollision' 20:51:53.090 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\modPuz.lua:627: in function 'gfDetectCollision' 20:51:53.090 C:\Users\Angela McCall\Documents\Corona Projects\Game\_BrickSliderPuzzle\GP1.lua:732: in function '?' 20:51:53.090 ?: in function \<?:190\>

 

It sounds like whatever you are passing there is no longer a display object. If you’ve somehow removed the display object, its table would still remain until you set it to nil as well. One reason why this might happen is because you overwrite the object at some point. Perhaps you return that objectOut over it or something.

Hiya,

After some more researching last night I kind of got to this point. As a result I’ve just about “fixed” the issue.
So thanks for taking the time to reply.

ANgela