How do I populate an array with words from an external dictionary file that are delimited by newline

0 favourites
  • 4 posts
From the Asset Store
Source File, music and art pack for Android Negotiator
  • I have an external text file with all the words, each on a newline. The file contains all the words of a dictionary. I would like to read the contents of the file into my construct 3 project and store them into an array with each individual word stored as an element in the array.

  • Does it need to be a text file, and will its content change often? In other words - do you need to read specifically that text file every time the game starts?

    If not, then it will be easier to create a new array file in the project and manually import all words from the file into it. If you create enough empty cells, you should be able to copy/paste all words at once.

    You will still need to request the array file with AJAX.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Yes, the external file is read once when the game starts. I've tried AJAX to read the file into a variable with AJAX.LastData which was successful. The problem I'm having is to split the variable data into individual words and storing the words into a Construct array. I can't get Construct to do it either using its native built-in events or JS code blocks. Nothing seems to work. I'm missing something!

  • Ok, if you definitely need to parse the text file, then here is the code:

    System Repeat tokencount(s, newline) times
    .. Array push back tokenat(s, loopindex, newline)
    

    's' is the variable containing AJAX.LastData. Make sure to set array default width to 0.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)