Select lines from a .txt file to display

0 favourites
  • 6 posts
From the Asset Store
Excel2JSON
$1.20 USD
60% off
Convert multiple Excel files into JSON files and import them into construct3.
  • Hi,I'm making a quiz game and to make it easier to get the questions in the game I am usinge AJAX to load a .txt file.

    I have so far managed to get the .txt file loaded and the first question to display in my text box by setting text to AjaxLastData.

    Even that took me ages to work out because I am such a noob.

    Is there an easy way to set the text to specific lines in the .txt so I can just have a list of questions that can be selected?

    Please don't tell me I need an array because that is definitely beyond me!

    Thanks,

    Elliot

  • AjaxLastData contains the integrality of your text file. You will have to parse it to retrieve the lines you want. I guess you could tokenize the data with the "newline" character (using tokenat). But it will be practicable only if you have one question per line. Otherwise you might want to take a look at XML.

  • I suggest you either using a special char and tokenate at it

    Imagine this:

    #TITLE OF QUESTION 1

    Blah, blah, blah

    Answers

    1. X

    2. X

    3. X

    #TITLE OF QUESTION 2

    ...

    You can get first question by using tokenat(yourtext,1,"#").

    And, inside the first question, you can get first answer by finding newline&"1.", second by finding newline&"2.", etc.

    I use a similar scheme in my game "caballo", where the "question" text is inside a textbox (I made that before files were avalable)

    http://www.scirra.com/arcade/puzzle/1090/caballo

    You could use XML or JSON instead if you want to make something more standarised, of course.

  • I just want to add I've uploaded to the arcade the program I use to debug my xml files, just in case you decide to use XML.

    It is here

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks Arcalaus- I think that will do the trick. I don't even need the answers- it's all very simple.

    I'll be setting it up on Monday- hopefully this will be the end of this thread!

    Cheers ;)

  • Cheers Magistross- the questions are all on new lines so a newline parse will be fine!

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