Search Unity

Accessing text file contents from url?

Discussion in 'Scripting' started by Flargy, Nov 9, 2018.

  1. Flargy

    Flargy

    Joined:
    Sep 5, 2014
    Posts:
    8
    Hi everyone.

    I am working on a mapmaking project.
    I currently save and load maps using text files in my project.
    Is there any way to load text file contents from a url?
    Say from dropbox, or a link in a forum?

    I have tried www.text, and ended up with is a bunch a page text containing my file name, but not my file data.

    Thanks in advance,

    Shane
     
  2. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
    Joe-Censored likes this.
  3. Flargy

    Flargy

    Joined:
    Sep 5, 2014
    Posts:
    8
    Hi Flavelius,

    Thanks for getting back to me.

    I had a look at your suggestion and I found it did much the same as before - returning a bunch of page webcode with my file name in it. Which is cool.

    This got me thinking that maybe I am approaching the problem the wrong way.
    I then thought I should explain what I am trying to do.

    My project is a map creation game where the maps are stored as texts files in the project.
    The content of these files are mostly a haphazard collection of numbers.

    What I was hoping to be able to do was have Player 1 be able to share a map by linking a text file of a saved copy of that map. Player 2 would, hopefully, be able to view that map by copying and pasting that maps link into Unity.
    Unity could then, again hopefully, be able to download the map's text file and use the text contained within to
    recreate a copy of Players 1's map that Player 2 could view.

    I was hoping that Players might possibly be able to share maps on forums, though I will admit I am at a bit of a loss as to how this might be done.

    Any thoughts would be appreciated.

    Many thanks,

    Shane
     
  4. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    Other than php, the easy way, but not most elegant, is to display your saved data as text in the Unity game. Then player can copy paste to forum for example.
    And vice versa, when loading back, copy from forum, or text file to unity game.
     
  5. Flavelius

    Flavelius

    Joined:
    Jul 8, 2012
    Posts:
    945
  6. Flargy

    Flargy

    Joined:
    Sep 5, 2014
    Posts:
    8
    Hi Antypodish,

    Thanks for getting back to me.

    I liked your ideas.

    It would be easy enough to modify my project so that it could accept raw copied map data through an input field.
    Map text files get quite large with larger maps, which would lead to massive walls of text needing to be copied and pasted. Another issue would be that missing or changing even a single digit in the raw map data would be enough to corrupt the data and make it unusable.

    Although I was hoping for in "In Project" solution to the sharing of maps, the following method would work:
    Visit forum (or youtube, blog, etc), and find a map (using description and picture).
    Download map text file
    Copy this map text in project/Maps directory
    Load up game, and then load up new map

    The above method would be a little time consuming but is intuitive and easy to do.
    What do you think?

    Thanks,

    Flargy
     
  7. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,769
    To reduce size of file, you could implement some algorithms,. For example instead plotting 10x10 cells = 100 cells of same tail, providing map is tailed, you can have some command indicating multiplier. So you end up with Command a, Tail type b, size x y. Similar for a making long wall.

    If is not on mobile, you can also save to txt as @Flavelius suggests.

    Btw, you don't need restart game after pasting to directory.