hello,
I am making a game that loading data from file
I used two ways ,worked on emulator but not on android phone
one using text file and choosing randomly from it
and another json file and loading it to table then choosing randomly from it
I tried many times and it doesn’t work
the last time I tried to save the table into file then load it and choose it worked
but that not what I want I just want it to load
thanks
Hi @imnimn,
We need more details to provide assistance. What kind of file (format)? What system directory is it located in? What is the code you’re using to read it in?
Have you followed these tutorials?
http://www.coronalabs.com/blog/2012/02/14/reading-and-writing-files-in-corona/
http://www.coronalabs.com/blog/2013/02/13/faq-wednesday-sub-folder-and-file-access/
Regards,
Brent
-it is just table of words and I will choose randomly one word from it
-it is located in documents directory
-I use the code in http://www.coronalabs.com/blog/2012/02/14/reading-and-writing-files-in-corona/ “reading file”
-actually the code is running right on emulator but the problem on the phone when I reach to load from file the application stop
the problem is that I want to read from this file only and the phone could not see the file
thanks.
So it’s a basic text file? Can you post the exact (full, case-sensitive file name) and the code you’re using to load it, including setting up the path for the file?
Thanks!
–this the code I used to load the file into table
json = require(“json”)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local contents = “”
local myTable = {}
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
myTable = json.decode(contents);
io.close( file )
–print(myTable[1])
return myTable
end
return nil
end
– and then Ijust load i as this
usrtab = loadTable(“Wordslvl1.json”)
I guess I shall mention that the application just load the file
and it never make update on it
-do you think that I should store the in the resource file
thanks
Sure, you can put this in the Resource directory if you’re just bundling this with the build, and don’t ever need to write/update it.
You’re sure this actual file is “Wordslvl1.json” in that case, capital “W” and all? Spelled exactly like that? Files aren’t necessarily case-sensitive on the computer, but on the device, they are.
Brent
yes it’s capital .
There is something I’ve read that if I update on Resource directory the phone will treat it as malware is that right?
Actually, I don’t know how to put the files in Resource directory
I would be grateful to you if you show how to do that
another thing I’m working on windows and I tried to create file on Resource directory (using code) but I could not
thanks alot.
The Resource directory is read-only, so you can’t update files within it. If you want to “bundle” files with your app that go in the Resource directory, you simply include them as part of the project build, in the core directory where “main.lua” is located. For example, you might have a series of text files that your app uses (reads from) during the runtime. These can be located in the Resource directory, but they can’t be modified later.
Brent
Thank you alot Mr, Brent
It works now
I’m really so grateful to you
Could I ask you another question?
I am working with characters and it’s to drag one character
I guess that I should enlarge it’s background using xml But ,I don’t know how
so could you help me Mr,Brent
Hi @imnimn,
We need more details to provide assistance. What kind of file (format)? What system directory is it located in? What is the code you’re using to read it in?
Have you followed these tutorials?
http://www.coronalabs.com/blog/2012/02/14/reading-and-writing-files-in-corona/
http://www.coronalabs.com/blog/2013/02/13/faq-wednesday-sub-folder-and-file-access/
Regards,
Brent
-it is just table of words and I will choose randomly one word from it
-it is located in documents directory
-I use the code in http://www.coronalabs.com/blog/2012/02/14/reading-and-writing-files-in-corona/ “reading file”
-actually the code is running right on emulator but the problem on the phone when I reach to load from file the application stop
the problem is that I want to read from this file only and the phone could not see the file
thanks.
So it’s a basic text file? Can you post the exact (full, case-sensitive file name) and the code you’re using to load it, including setting up the path for the file?
Thanks!
–this the code I used to load the file into table
json = require(“json”)
local path = system.pathForFile( filename, system.DocumentsDirectory)
local contents = “”
local myTable = {}
local file = io.open( path, “r” )
if file then
– read all contents of file into a string
local contents = file:read( “*a” )
myTable = json.decode(contents);
io.close( file )
–print(myTable[1])
return myTable
end
return nil
end
– and then Ijust load i as this
usrtab = loadTable(“Wordslvl1.json”)
I guess I shall mention that the application just load the file
and it never make update on it
-do you think that I should store the in the resource file
thanks
Sure, you can put this in the Resource directory if you’re just bundling this with the build, and don’t ever need to write/update it.
You’re sure this actual file is “Wordslvl1.json” in that case, capital “W” and all? Spelled exactly like that? Files aren’t necessarily case-sensitive on the computer, but on the device, they are.
Brent
yes it’s capital .
There is something I’ve read that if I update on Resource directory the phone will treat it as malware is that right?
Actually, I don’t know how to put the files in Resource directory
I would be grateful to you if you show how to do that
another thing I’m working on windows and I tried to create file on Resource directory (using code) but I could not
thanks alot.
The Resource directory is read-only, so you can’t update files within it. If you want to “bundle” files with your app that go in the Resource directory, you simply include them as part of the project build, in the core directory where “main.lua” is located. For example, you might have a series of text files that your app uses (reads from) during the runtime. These can be located in the Resource directory, but they can’t be modified later.
Brent