- Home /
Trying to download and show contents of text file
Something that seems so simple, yet all the console shows is a bunch of question marks when I use this code. All I want to do is be able to read a small string and check if there is a new download available for the game. Then, I can tell the player "Hey there is a new version available. Want to download it?" Then I can direct them to a link or something.
var url = "http://www.mackenziemelby.com/download/i/mark_dl/u/4011917382/4618859823/sync_ExplosiveDrive.txt";//?dl=1
var www : WWW;
function Start(){
www= new WWW(url);
yield www;
Debug.Log (www.text);
}
function Update(){
if(www.progress<1)
print ("loading"+www.progress);
}
checked www.error no errors. Seems to download just fine. It's just www.data and www.text both return "����" as a string.
You try to print the text in your Start()
function but it looks like the Update()
function is accounting for a case where it hasn't been downloaded, yet. $$anonymous$$aybe you should be putting your Debug.Log(www.text);
call in an else
statement after your if(www.progress<1)
?
Answer by tigertrussell · Feb 26, 2015 at 12:21 AM
From my comment, try this:
var url = "http://www.mackenziemelby.com/download/i/mark_dl/u/4011917382/4618859823/sync_ExplosiveDrive.txt";//?dl=1
var www : WWW;
var spamLimiter = false;
function Start() {
www= new WWW(url);
yield www;
// Debug.Log (www.text);
}
function Update() {
if(www.progress<1) {
print ("loading"+www.progress);
}
else if(!spamLimiter) {
Debug.Log(www.text);
spamLimiter = true;
}
}
Still giving me the question boxes in the console: "����" No idea what that means or why it's appearing.. The actual txt file I am referencing should just print out "Testing stuff".
Oh! I finally figured out what was going on. It's a bug (or feachur) in Unity. If you look at "var url" which is a public variable, is shows the right address in the code, but for some reason, an old address was stuck in the inspector. Yeah.. all because the code doesn't override the inspector like it did in the old versions of unity. Huh.. problem solved.
Wow... I had the exact same problem, I had my url string set to public and it was filled in to an image in the editor.
I don't think some people realize how helpful it is when they come back and post how they eventually solved ridiculous things like this, so I am commenting to let you know your comment saved me a decent amount of head-banging-against-wall.
Your answer
Follow this Question
Related Questions
Best way to manage stats in a text file 2 Answers
Move a Camera with a Data from a Text file after Build. 1 Answer
Optimize the reading of a text file? 1 Answer
I cant read the file i wrote, unless i reload it in VS. 1 Answer
How can I read data from a text file, putting a large amount of data into structures 2 Answers