Jump to content

Load Text Files Of Words Into Arrays?


JeZxLee
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Hi 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 method

var 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.
Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...