I’m trying to select a pic from devices library and save it to a custom folder. Then I want to retrieve the same pic from that custom folder. Here’s my code
main.lua ---------------------------------------------------------------------------------------- lfs = require "lfs" docs\_path = system.pathForFile( "", system.DocumentsDirectory ) success = lfs.chdir( docs\_path ) new\_folder\_path = nil dname = "EiB\_Uploads" if ( success ) then lfs.mkdir( dname ) new\_folder\_path = lfs.currentdir() .. "/" .. dname end \_G.myGameSettings = table.load( "myGameSettings.json" ) if( not myGameSettings ) then myGameSettings = {} myGameSettings.daddy = "images/templateDaddy.png" table.save( myGameSettings,"myGameSettings.json" ) end --------------------------------------------------------------------------------------- activity.lua -------------------------------------------------------------------------------------- local function loadScene() local daddy = display.newImageRect(UF,myGameSettings.daddy,\_W/5,\_W/5) daddy.x = 10 daddy.y = 10 end loadScene() local function onPhotoCompleteD(event) myGameSettings.daddy = new\_folder\_path.."/".."Daddy.jpg" table.save( myGameSettings,"myGameSettings.json" ) loadScene() end local function uploadImgDFunc(event) if (event.phase == "ended") then if media.hasSource( media.PhotoLibrary ) then media.selectPhoto( { mediaSource = media.PhotoLibrary, listener = onPhotoCompleteD, destination = {baseDir=new\_folder\_path, filename="Daddy.jpg"} } ) else native.showAlert( "Corona", "This device does not have a phot library.", { "OK" } ) end return true end end UF\_uploadImgD:addEventListener( "touch", uploadImgDFunc )
I’m getting this error : Attempt to index local daddy a nil value
I tried manually copying that pic to the specific folder (in my windows machine). But same error.
I get the same error on device too. I’m finding it very difficult to test it on simulator as library is not available on simulator. So I’m not even sure if the selected pic is copied to the custom folder or not.
Almost tried everything but no luck. Someone please guide me on where I may be going wrong