JeZxLee Posted January 13, 2015 Share Posted January 13, 2015 Load Text Files Of Words Into Arrays? Hi, My team and I are working on a new HTML5 word game.We have dictionary split into 26 text files.How can we load each text file of words into arrays?Any help would be appreciated, thanks! JeZxLee Quote Link to comment Share on other sites More sharing options...
JeZxLee Posted January 13, 2015 Author Share Posted January 13, 2015 Hi, We have an alpha version for both Windows and Linux here:LF5-WinLinux-Alpha5.zipif you would like to look at the game or source. We plan to port it to HTML5/JS... JeZxLee Quote Link to comment Share on other sites More sharing options...
VizuaaLOG Posted January 13, 2015 Share Posted January 13, 2015 Load Text Files Of Words Into Arrays? Hi, My team and I are working on a new HTML5 word game.We have dictionary split into 26 text files.How can we load each text file of words into arrays?Any help would be appreciated, thanks! JeZxLeeHi JeZxLee,I am assuming you are running your game through some kind of server so that asset loading etc works, so you could use Ajax to load the text file then split the returned string. If I am not mistaken then below is one methodvar xmlhttp = new XMLHttpRequest();var myData;xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState === 4 ) { if(xmlhttp.status === 200){ myData = xmlhttp.responseText.split(" "); } else if(xmlhttp.status === 400) { alert('There was an error 400') } else { alert('something else other than 200 was returned') } }}xmlhttp.open("GET", "ajax_info.txt", true);xmlhttp.send();You would need to put that into a function and return the result or something because of it being asynchronous. And if the words are on each line then replace the space inside split with \n instead. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.