Just jumping in here a few months late, but I have been running code to do similar things, but have found a problem that I cant see the cause. Probably not easy to decide any suggestions or help, from this description, but here goes…
I have been downloading a text file and writing it to a file with no problems.
params.progress = “download”
params.response = { filename = “results.txt”,baseDirectory = system.DocumentsDirectory}
network.request( _G.set.Url, “GET”, networkListener, params )
Even detecting network errors and falling back to prior saved file data ok. I then read back the file, one line at a time to parse each line for the apps use and then build a table for showing later in several scene treeviews, which is also working fine.
There are many scenes and each scene picks up the table ok, which is held in a module locally and the module returns the table name at the end of the module locals.ResultsReadList=ResultsReadList return locals.
This is reference in each scene via local Results = require “libname.modulename” and #Results.ResultsReadList
The download file is getting rather large so to avoid taking up to much mobile hard storage I thought I would modify the content and truncate the string in each line to 50 chars, and then write back out the table as a Json file created for use in the treeviews. TableFile.save(ResultsReadList, “Results.json”,system.DocumentsDirectory) (a general sub written)
This also works fine while the wifi connection is working. So I was very pleased and ready to write code to delete the ‘results.txt file’ to save space.
BUT, now when I test without the wifi on, the application scenes fail to find the table data content. #Results.ResultsReadList shows zero. Yet when wifi is connected each scene sees #Results.ResultsReadList=52
Debugs shows that the module checks the internet and if not active reads the last created JSON file into the table ok (as it does also when the wifi is on).
Print statements show the table has been loaded and has content in the module (as it does with wifi connected) and the table size #ResultsReadList =52 and a loop prints out each table entry (as it does with wfi connected). So it is definitely work either way in the module regardless of wifi.
When the scenes are loaded and the wifi is off they find the #ResultsReadList =0 , no content. Run with wifi on and they all work fine going the exactly the same load table json code. The file has data (new or prior) in all wifi tests on or off and the module level.
I cannot see where the ResultsReadList table gets deleted (if at all). The only difference is that with wifi on, extra IF code writes out the Json file. That is the only difference I can see. The table is initially created then by ResultsReadList[#ResultsReadList+1] = string.sub(readResultLine,1,50) in a loop (but this is a red-herring I think)
I have even deleted the ResultsReadList={} after being saved on the Json file(or when it is not saved due to no download) in all cases. The table is only ever created via the Json load table in all cases. Some how the table is loosing scope or being deleted between module code and scene change but why I cannot see or understand.
Alec