Getting Information from a .txt

So I’m trying to get information from a .txt in my dropbox but when I run it in the editor I am greeted to this instead:

Here is the script:

using UnityEngine;
using System.Collections;

public class MOTD : MonoBehaviour {
	public string URL = "https://www.dropbox.com/s/psyh1uiq3hroemj/lol.txt";
	public string Info;
	public bool dwnlded;
	public WWW myWWW;
	void Start(){

		myWWW = new WWW(URL);

	}

	void FixedUpdate(){
		if(myWWW.isDone && !dwnlded){
			Info = myWWW.text;
			dwnlded = true;
			Debug.Log (Info);
		}
	



	}



	void OnGUI(){
		GUI.Label (new Rect(10,10,9000,9000), Info);
	}
}

Can anyone explain why this is happening?

Thats the html of the page you’re loading. It looks like its using Javascript to pull the info of your text file and display it. If the text was embedded in the html, you could read it directly using WWW, but its not. My advise would be use your own hosting and embed it in html. I did this a while ago for a project and it worked perfectly. So recap, unless you find a way to pull info from the JS of the page, I doubt you’ll be able to use this method with dropbox. Hope that answers your question.

Hey,

Currently, it seems as if you’re getting the HTML version of the site. I headed over the the dropbox link, ‘inspected element’, and saw the same thing you provided in the screenshot.

Here’s a way to fix it that wouldn’t necessarily answer your question, but it will make it work:

Create a text file in your public dropbox folder, put your text in, save it, and name it Whatever.html.(‘Whatever’ can be changed to anything you want.) Then, copy the public link, and paste it into your script/inspector. It should work fine. Well anyways, it worked for me.

If you need further assistance or it didn’t work, feel free to ask.

Best of luck,

SeeSahrp

So, here’s how I look at it. You want to get the Message of the day from a webpage, so let’s do that.

C#:

using UnityEngine;
using System.Collections;

public class downloadMOTD : MonoBehavior
{
	private bool downloaded = false;		// Have you downloaded the data yet?
	private string MessageOfTheDay = "";	// Store the message of the day
	
	public void OnGUI()
	{
		// If you click the button,
		if(GUI.Button(new Rect(50, 50, 200, 20), "Get The Message Of The Day")) {
			// Get the MOTD
			this.getMOTD();
		}
		
		if(this.MessageOfTheDay !== "") {
			// If the MOTD isn't null, display it
			GUI.Label(new Rect(50, 100, 300, 20), this.MessageOfTheDay);
		}
	}
	
	public void getMOTD()
	{
		// Create a form to post to your PHP file
		WWWForm motdForm = new WWWForm();
		// Add the type field, using 0 or 1 for the param
		motdForm.addField('type', 0);
		// Create the WWW page, and post the form to it.
		/**
		 * With this, I used WAMP to host my local file.
		 * If you're unfamiliar with it, you can go to http://www.wampserver.com/en/
		**/
		WWW motdPage = new WWW("C:\wamp\www\motd.php", motdForm);
		// Wait for the sites response
		StartEnumerator(WaitForResponse(motdPage));
	}
	
	public IEnumerator WaitForResponse(WWW www)
	{
		// yield return www -> Wait for the site to respond, then continue to everything else
		yield return www;
		
		// If there was an error, tell the user, and log the error
		if (www.error == null) {
			this.MessageOfTheDay = "Sorry, there was an issue getting the message of the day.";
			Debug.Log(www.error);
		} else {
			// Otherwise, display the MOTD
			this.MessageOfTheDay = www.text;
		}
	}
}

PHP:

<?php
	if(isset($_POST['type'])) {
		// If you submitted a form with a ['type'] array key,
		switch($_POST['type'])
		{
			// Cycle through some options for type
			default:
				// Does nothing, is a catch for any unforeseen errors
				break;
			case 0:
				// Return a local copy of the MOTD
				echo "This is the message of the day.";
				break;
			case 1:
				// Return a database copy of the MOTD
				
				// Connect to a MYSQL account
				mysql_connect('localhost','root','password');
				// Select your MOTD database
				mysql_select_db('motd');
				// Look for the MOTD in the database table
				$query = mysql_query('SELECT * FROM motd');
				// Create an associative array, will return $results['title'];
				$results = mysql_fetch_assoc($query);
				// Set MOTD as the result
				$motd = $results['title'];
				// print the MOTD
				echo $motd;
				break;
		}
	}
?>