loadText and saveText

I seem to be having an issue with the loadText() and saveText() functions. When I use them in the Codea environment, no problem at all. When I export my project to Xcode, the functionality becomes very limited.

For instance, in the App environment, loadText() will only work if I’ve exported the project with the Document that I’m loading already created and exported with the project. If I try to use saveText to overwrite it, it will not update.

In the App environment, if the document doesn’t exist, saveText() will not create it (or it simply isn’t loadable through loadText()).

This is all true, regardless of the document path. I’ve tried just the filename, with Document:, and with Dropbox: as a prefix.

In the Codea environment, all of the above works as expected.

Any thoughts?

This is interesting. I remember when I examined the app bundles created by the Xcode simulator, it seems as if there are two sets of asset pack folders. One is in the app bundle (ie not meant to be modified), and one is in the app data bundle(which can be modified). Sorry, am away from my Mac just now so can’t verify this. If I remember, the asset management commands Readtext saveText readImage saveImage pointed to the folders in the app bundle (ie pre-existing bundles). However, the Lua io and file commands, accessed via the HOME variable, pointed to the other set of folders.

In Codea, there is no distinction, only one Dropbox asset folder.

But perhaps in the app environment, we’re meant to use Readtext etc only for pre-existing, bundled assets, and Lua’s file io commands for data created by the user of the app.

I looked into this because I found that in Xcode I could no longer read my 3d models using file/io because the home variable pointed to the wrong Dropbox folder, I could only read them using Readtext.

So, for user-created content, try using the Lua file io commands, see if that helps. They’re a bit more fiddly, but you could easily write a wrapper function for them.

I’m having the same problem. @yojimbo2000, How would u use the I/o functions to work? When I tried it last, I still have to include a root directory (e.g. os.home()) but that didn’t work either. I was advised to use read text and savetext, but now it looks like this doesn’t work either. Readtext is reading to the right directory but saveText is accessing a different directory.

Given what u say above, I will try using Dropbox instead of documents for read text/savetext. But would really appreciate your tips/help on this.

Yeah, I’ll look into this. It would be good to get this documented properly so that we can make a feature request/ bug report as appropriate. Although Lua file io is fine for text files, I’m worried that it might not work for images.

@yojimbo2000 @zapaper @johnpoore hi … is this solved?

I think that it is not yet. I met a funny thing about this today.

for the same trouble, pls check my question:

after export to xcode, the txt file in codea is in a bundle folder.
so os.getenv cannot find the route. then os.getenv is useless.

to solve this. I cancle the OS.getenv…etc. I think , readtext can work, then savetext must work. whererever the folder is. readtext only read the txt in assets folder in the bundle foder. and savetext must do save to the save route.

then I changed my code. it work well in codea. and work well in simulater . I enter the real route of the txt file ( all mp3, button img and txt files are in the bundle folder) … find my app can save text in the txt file.

but when I am happy, I found it cannot work in true phone …
i test by iphone se. anyhow it cannot save to the txt file.

how to do then… big head now. …

sorry. my old question is here.
https://codea.io/talk/discussion/8962/hello-need-help-about-txt-file-downloaded-and-rewrite-in-app-i-am-mad-already#latest