LoadStrings on 000webhost

Hi,

I am running a website through 000webhost which has 2 .pde files attached. One works and the other doesn't. I have realised the other one does not work because of the loadStrings function.

String[] highscoreList = loadStrings("highscores.txt");

I assume it is to do with the directory of the highscores.txt but I am not sure. Any help would be appreciated. The location of the text file is in the same location as the html and .pde on the server.

Thanks, Zac

Answers

  • You might have to put it in a data directory. That is, the data directory (named "data") is in the same place/level as the pde, and the file of strings you want to load is in the data directory.

    Or try loading "../highscores.txt", a relative path.

    Or you can also specify the full URL.

  • None of those seemed to help unfortunately, thanks though.

    Is it likely to be a problem with the code or could it be the server host?

  • I managed to get it working using this tutorial

    http://www.learningprocessing.com/tutorials/external-data-into-processing-2/

    And using a php file instead. Do not know why the other way did not work but at least I have a working alternative

  • Just for future reference: did you check the browser console (usually accessible via F12)? You'll see the results of failed data requests there; and importantly the path being used to access the files. Assuming you're loading files local to the HTML file I wouldn't expect the usual x-domain issues that often crop up; so would assume this was a path issue that should be easy to resolve...

  • I did not realise that was possible. I just tried it though and can not seem to find the file path though.

  • Answer ✓

    After hitting F12 there are quite a few options. Console is handy for debugging: and will definitely show details of a failed request (if there is one), including the URL. You can also output the value of a variable to the console using console.info(variableName); in the same way you'd use print()...

    For more detail on network activity (including successful requests) switch to the 'Network' tab and hit F5 to reload. You'll then see all requests the web pages makes. Clicking an entry gives you even more detail on that entry...

    Chrome probably has the best tools for debugging JS; but Firefox dev edition is pretty good too...

  • Thanks, it turns out that .txt files are restricted on the server I am using to host the website. Thus explaining why a .php works instead.

Sign In or Register to comment.