Hi
I have some trouble undestanding how to get something from a .txt file. Can anyone point me to some good reading or tutorials on this as this things I found on the forum did not really explain it enough for me??
I have 3 things I need to solve in my app:
1. Saving a variable from inside the app for later use (next time the user opens the app)
2. I have up to 150 images.
3. I have up to 150 texts with up to 200 words
At the moment I am looking at solving 2 and hope that could also be used for 3.
@pie said I could look into this code for a way to have my image references in a textfile instead of naming them all in the LUA code. But I only get it to return a nil-value... I am not sure if it does what I am trying to achieve.
function getPackTextures(packname)
local textures = {}
local file = io.open(packname..".txt")
if file then
local parsed
for line in file:lines() do
parsed = line:split(", "))
textures[#textures+1] = parsed[1]
end
-- now variable textures contains all texture names from pack
else
print("no pack found")
end
return textures
end |
In the tutorial section I found a tutorial on saving/loading data But it just show some code and dosn't really explain what is happening... what is w+ and |D|
local file=io.open("|D|settings.txt","w+")
file:write(Player .. "\n")
file:write(Score .. "\n")
file:write(HiScore .. "\n") |
Comments
(r)ead
(w)rite
e(x)ecute
so +w means you can open the file read contents and write to file.
|D| means documents directory in Gideros.
See here for more info:
http://docs.giderosmobile.com/file_system.html
I believe that you were missing the string split function by OZApps
Be aware of the alhabetical sorting of images in the texture pack, which should match your captions order.
With some work you should also be able to get the caption from the file names.
To save/load data you can use dataSaver by ar2sawseen:
http://appcodingeasy.com/Gideros-Mobile/Save-and-load-data-module-for-Gideros-Mobile
Likes: Den_er_da_hvid, antix
I believe I was missing many things ;-)
I almost got save/load to work when playing with Cordova, but when I look at their reference library it doesnt look like I can use the same example codes in Gideros.