I have a list of file id’s of images in my drive that I put into a link to download, I’m trying to download all of them to the document directory and save their names in a table to be accessed later.
My problem is, while it downloads, it runs other commands but I want it to wait until it downloads all the images before moving forward. I can’t use sockets cause sockets don’t work with “GET”. Here’s my code so far:
if event.response then local decodedResponse = json.decode(event.response) local slideImages={} local function networkListener( event ) if ( event.isError ) then print( "Network error - download failed: ", event.response ) elseif ( event.phase == "began" ) then print( "Progress Phase: began" ) elseif ( event.phase == "ended" ) then print( "downloaded" ) table.insert( slideImages, event.response.filename ) end end for i = 1, #decodedResponse.files do local params = {} params.progress = true network.download( "https://drive.google.com/uc?export=download&id="..decodedResponse.files[i].id, "GET", networkListener, params, decodedResponse.files[i].name, system.DocumentsDirectory ) end goToNextScene()
The code calls the “goToNextScene()” before all images are downloading and it causes and error.
I’d appreciate the helps thanks!
I know a solution would be to call the next download from the listener but I can’t figure out how to do this and stop it from moving forward.