Hi there,
Not sure if i’m committing a faux pas here, but I thought i’d check and ask for your opinion!
I’m currently using a bunch of sound effects for my game as _G. variables set in main.lua (i’m still using Director class by the way). The main reason is primarily because i’ve hit a problem with using 200 local variables upvalue error (something along these lines) so since these sound effects are used throughout my all my .lua files i thought of setting them as _G.
So, i’ve currently got a bunch of: _G.sound1=audio.loadSound(“assets/sound1.wav”) etc in my main.lua. And in my other .lua fles, i set a local soundEffect variable and play the sound using: local soundEffect=audio.play(_G.sound1); This means, at the end of these .lua files, i simply: audio.stop();soundEffect=nil;
Because i’m using globals here, how do i (or do i need to) remove these? Normally, if it was a local variable i’d also add: audio.dispose(sound1);sound1=nil.
Just wondering, would the following be better (so, still using _G. and inserted in main.lua):
local function onSystem(event) if event.type == "applicationStart" then \_G.sound1 = audio.loadSound("assets/sound1.wav") etc... elseif event.type == "applicationExit" then audio.dispose(sound1); sound1 = nil; Runtime:removeEventListener( "system", onSystem ) --note: do i also need to set this here? end end Runtime:addEventListener( "system", onSystem )
Would this approach be ok and do you see any issues with this?
Thanks for reading!
Cheers,