Getting a .txt file onto the iPhone

Discussion in 'iOS Development' started by Timbecile76, Feb 24, 2011.

  1. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Hi guys,

    I've got an app that stores its level data in a couple different .txt files. It reads, parses, and can write the text files just fine.

    Here's my problem. One of the text files I want to be able to be downloaded from a server. That works fine. The other one I want to come from the build. For some reason, even though I have a documents folder (with the txt files) inside the asset folder, when I do a build, it doesn't seem to copy the txt files over to the iPhone. (my reader function errors out saying the file doesn't exist)

    what do I have to do to get the txt file from the Asset folder into the iPhone build?
     
  2. mindlube

    mindlube

    Member

    Joined:
    Oct 3, 2008
    Messages:
    993
    Drop it into the Resources folder
    That's what I've done for localization strings.
     
  3. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Where is the Resources Folder? Is that somewhere in the Assets folder that I'm missing?
     
  4. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,589
    Its in there after you created it within the Assets folder
     
  5. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    So I created a Resources folder under /Assets, dropped the text files in there, built the game, and the iphone is still reporting that the files don't exist
     
  6. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,589
    and you loaded it through
    Code (csharp):
    1.  
    2. TextAsset test = Resources.Load("nameOfTextfile") as TextAsset;
    3. Debug.Log(test.text);
    anything thats in the project will not end as distinct accessable file on the device (with exception of the StreamingAssets folder, unsure though what types are supported there), they will end in as assets you load with Resources.load or have assigned directly on a component
     
  7. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Is that Javascript?

    When I tried your code I got a "; expected" error.

    I tried it this way:

    Code (csharp):
    1.  
    2. var text : TextAsset = Resources.Load("nameOfTextfile");
    3.  
    Which gave me an "Ambiguous Resources" error
     
  8. defjr

    defjr

    Member

    Joined:
    Apr 27, 2009
    Messages:
    436
    Does naming your var something other than 'text' make a difference?
     
  9. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Doesn't matter what the variable name is. I've changed it a hundred times and it still doesn't work.

    I don't get it. I typed it in exactly like what was shown in the example in the scripting docs and I'm still getting the "ambiguous reference" error.
     
  10. kenlem

    kenlem

    Member

    Joined:
    Oct 16, 2008
    Messages:
    1,457
    Do you have multiple files in that directory with the same first name but different extensions?
     
  11. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Nope. I have two files: extraLevels.txt and levels.txt
     
  12. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,589
    expand the Resources.Load call to Resources.Load("textFilePath", typeof(TextAsset)) in C# or Resources.Load("textFilePath",TextAsset) in UnityScript so it explicitely filters for text assets only
     
  13. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Tried that already. Same Problem.

    I'm using the Indie version of 1.7 (for the iPhone). would that have anything to do with it?
     
  14. Timbecile76

    Timbecile76

    New Member

    Joined:
    Jul 8, 2009
    Messages:
    227
    Alright! Got it working.

    Instead of worrying about using Resources.Load or anything like that, I just created a text Asset var and dragged the .txt files onto them in the editor. works much easier! Don't know why I didn't think of that sooner!