Guys, im new on lua and working on saving record of the game into a text file. For example after the game is finished, save current score and gold collected. Can you guys show me how to save information into a text file?
Hi Alex, i have already read it. Means that whenever we wanna store data we need to save it into a table format and cant directly write into external text files? Correct me if im wrong!
In my testing, changing the extension to be saved from “json” to “txt” saves the data in a text file. Are you encountering problems in your testing?
Hi, if i wanna change the path location for the saved file then i should change system.DocumentsDirectory to "local _defaultLocation = “C:\Users\Desktop\SpaceBlock” ? But i couldnt find the json file in the SpaceBlock folder ermm
It also state attemp to save at an invalid location…
what i did is executing
loadsave.saveTable(results, “results.json”, “C:\Users\\Desktop\SpaceBlock”)
and in loadsave.lua
local _defaultLocation = “C:\Users\Desktop\SpaceBlock”
Anything wrong?
Basically, since Corona-made apps have their own directory structure, you won’t be able to save files to other directories besides ones accessible to the app. Meaning, you can’t save your files to any random place on your computer, because other people won’t have those directories on their devices.
Go over the guide again, paying specific attention to the system.pathForFile() API. This outlines basic directory structure and what you can and can’t do in Corona.
https://docs.coronalabs.com/api/library/system/pathForFile.html
Hi Alex, i have already read it. Means that whenever we wanna store data we need to save it into a table format and cant directly write into external text files? Correct me if im wrong!
In my testing, changing the extension to be saved from “json” to “txt” saves the data in a text file. Are you encountering problems in your testing?
Hi, if i wanna change the path location for the saved file then i should change system.DocumentsDirectory to "local _defaultLocation = “C:\Users\Desktop\SpaceBlock” ? But i couldnt find the json file in the SpaceBlock folder ermm
It also state attemp to save at an invalid location…
what i did is executing
loadsave.saveTable(results, “results.json”, “C:\Users\\Desktop\SpaceBlock”)
and in loadsave.lua
local _defaultLocation = “C:\Users\Desktop\SpaceBlock”
Anything wrong?
Basically, since Corona-made apps have their own directory structure, you won’t be able to save files to other directories besides ones accessible to the app. Meaning, you can’t save your files to any random place on your computer, because other people won’t have those directories on their devices.
Go over the guide again, paying specific attention to the system.pathForFile() API. This outlines basic directory structure and what you can and can’t do in Corona.
https://docs.coronalabs.com/api/library/system/pathForFile.html