Hey all … I am working on a program that will take in input from a website… and thus far I have gotten it to properly download the text file every 5 seconds … but it doesn’t seem to be grabbing the new input with each download… for instance… When I start the program … the text file has say… 17 lines… then WHILE the program is running a user adds to that text file via a very simple php form… this new (18th) line is appended to the file … but on the next download (which is confirmed in Unity) it still reports back 17 lines.
here is a snippet of the Start function:
function Start ()
{
url ="http://wlbablahblahblah/desires2.txt";
while(true)
{
yield new WaitForSeconds(intervalTime);
Debug.Log(Time.time);
desirePage = new WWW(url);
yield desirePage;
if (desirePage.isDone)
{
Debug.Log(desirePage + " is DL");
desireString = desirePage.text;
updateNumDesires(prevNumDesires);
buildAstroWithDesire(numDesires);
}
}
}
I have a feeling that the text file is being cached in some way, because when I stop / start the game up again, I get the new (18th) line included. Any input on how I can get this to get the newest info DURING runTime?
Thanks
-s
Yeah that’s a common problem in Flash as well, luckily there’s an easy solution (at least in Flash and I am assuming it holds true in Unity as well).
One hacky way is to just append some random GET parameter to the end of the url so instead of
http://wlbablahblahblah/desires2.txt
you just have
http://wlbablahblahblah/desires2.txt?random=123241
I THINK the value of random doesn’t even need to change, just the fact that there is any GET parameter tells Flash(Unity?) that this URL is dynamic and therefor we shouldn’t use the cache.
I said it’s hacky because it doesn’t make sense to send GET parameters to a page is not a page, but a text file… it’s possible that some websites won’t like this and will give you an address not found error (though that’s quite unlikely)
The real way to go about this is to just have a “desires2.php” file which prints the text. Instead of storing the user-input in a text file you would store it in a database, and then retrieve it before printing. Note: You would still need to have a GET parameter so Unity knows it’s not a static page.
WWW when running in the webbrowser will use and comply to standard browser caching, just to explain why the solution Antitheory has explaines is required.
Or one should say: its required if you went the lazy way and didn’t use the standard way in HTTP to do the request as “non cached”, but in this case it will always go online, not use data from browser cache