I’m not entirely clear what the difference is.
But after testing, I came up with a conclusion of when to use “local” before a function.
Here’s an example:
local isAudioPlaying = false;
local objSnd = audio.loadSound("myfilepath.mp3");
local function runSoundFunction(e)
if(e.phase=="began" and isAudioPlaying==false) then
isAudioPlaying = true;
audio.play(objSnd, {onComplete=donePlaying});
end
end
--do not put "local" before this function
function donePlaying(e)
isAudioPlaying = false;
end
Runtime:addEventListener("touch", runSoundFunction)
I used to have “local” before function donePlaying and it wasn’t detected inside the runSoundFunction
Why is that?
In retrospect, why do when do we need to use local for variables? And when is best not to?
[import]uid: 154122 topic_id: 27320 reply_id: 327320[/import]
[import]uid: 21331 topic_id: 27320 reply_id: 111013[/import]